I was trying to show the address in google map in my iphone app.
I tried to use
NSString * theAddressString =......;
NSString * query = [NSString stringWithFormat:#"http://maps.google.com/maps?q=%#",theAddressString];
NSString * urlString = [query stringByAddingPercetntEscapesUsingEncoding:NSUTF8StringEncoding];
[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString];
Google map can not find some addresses we provided.(Some Japanese or Chinese addresses) But if I saved the address to iPhone contacts. And then pressed
the contact's address link. It will jump to google maps,though google map first alerted that "can not locate the address", after I confirmed the alert message, another view would display the location in the google map or show the address in the nearby.
So iPhone's "Contact" app may use other apis to filter the address string to locate the address or using some king of "fuzzy search".
Does anybody know how do they achieve it?
I really appreciate your help.
Try out the following one and let me about the status of solution.
NSString * theAddressString =......;
NSString *latlong = [[myLatitude stringByAppendingString:#","]stringByAppendingString:myLongitude];
NSString * query = [NSString stringWithFormat:#"http://maps.google.com/maps?q=%##%#",[theAddressString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//NSString * urlString = [query stringByAddingPercetntEscapesUsingEncoding:NSUTF8StringEncoding];
[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString];
New Code with give address:
NSString *theAddressString = #"東村山市野口町1-3-49 アマドムス 102, 東京都, 日本";
NSString *urlString=[NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%#&output=csv",[theAddressString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSArray *listItems = [locationString componentsSeparatedByString:#","];
float latitude=0.0;
float longitude=0.0;
if([listItems count] >=4 && [ [listItems objectAtIndex:0] isEqualToString:#"200"]){
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
}
else{
NSLog(#"Error");
}
NSString *myLatitude = [NSString stringWithFormat:#"%f",latitude];
NSString *myLongitude = [NSString stringWithFormat:#"%f",longitude];
NSString *latlong = [[myLatitude stringByAppendingString:#","]stringByAppendingString:myLongitude];
NSString * query = [NSString stringWithFormat:#"http://maps.google.com/maps?q=%##%#",[theAddressString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:query]];
I have checked the query string with google map and it is showing me the pin in Google map.
Related
I'm developing an application that makes the user call a specific number depending on their current position using NSDictionary. This position is displayed on a label. Now, if the user is in a position that is not included in the NSDictionary, it calls "6588". How do I change that number to a number of my choice?
placemark = [placemarks lastObject];
_addressLabel.text = [NSString stringWithFormat:#"%# %#\n%# %#\n%#\n%#",
placemark.thoroughfare, placemark.subThoroughfare,
placemark.postalCode, placemark.locality,
placemark.administrativeArea,
placemark.country];
- (IBAction)phone { [[UIApplication sharedApplication] openURL: [NSURL URLWithString:#"tel:%#"]];
NSDictionary *localityToPhoneNumber = #{#"London": #"123456",};
NSString *phoneNumber = [localityToPhoneNumber objectForKey:placemark.locality];
NSString *tel = [NSString stringWithFormat:#"tel:%#", phoneNumber];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:tel]];
Thank you very much in advance.
You can check is the key in the dictionary exists and if it doesn't exist you can call the default number, which is in your case 6588.
Something like this:
if (![localityToPhoneNumber objectForKey:placemark.locality]) {
// Call default number
} else {
// Call the number for the locality
}
In my iPhone app I am using Google API. One thing I have to do is I have a drop down of countries and when I select any country, i need to fetch all the cities of that country. Is it possible with Google API or I have to use any other. Please suggest!
Thanks-
The google Geocoder API returns JSON , It is just a kind of a web service which uses GET method
And This is the Google Gecoder API and This is the link for that web service and in this link i have given the region name as london. you can give you country name
Note: You need to include SBJson library to your code.
At the end of that link i have appended address, if you append address- you need to give the region name (or) if you append latitude and longitude, you need to give coordinates and it will return the results accordingly.
And the code for calling google api will be like this
//Call the Google API
NSString *req = [NSString stringWithFormat:#"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%#", esc_addr];
NSLog(#"The get address is %#", req);
//Pass the string to the NSURL
NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL];
NSLog(#"The result is %#", result);
//Initialize the SBJSON Class
SBJSON *parser = [[SBJSON alloc] init];
NSError *error = nil;
//Get the resullts and stored in the address array
addressArray = [parser objectWithString:result error:&error];
//Get the latitude values for the given address
NSDictionary *dict = [[[addressArray valueForKey:#"results"] valueForKey:#"geometry"] valueForKey:#"location"];
self.latitudeValue = [[dict valueForKey:#"lat"] objectAtIndex:0];
self.longitudeValue = [[dict valueForKey:#"lng"] objectAtIndex:0];
NSLog(#"LAT : %#",self.latitudeValue);
NSLog(#"LONG : %#",self.longitudeValue);
I have just given an idea, you can get all the names in form of Short name, Long name etc in the JSON Response there
It is convenient to use "– reverseGeocodeLocation:completionHandler:" method to Reverse Geocoding a Location. But how to obtain all locations in a region.
ps. If there are several places in a region. How could I use the region information to find out all the places? Such as reverse geocoding a location, given a coordinate, return a location. Here I wanna give a region, return all locations in the region.
There is a google Geocoder API which returns JSON , It is just a kind of a web service which uses GET method
And This is the Google Gecoder API and This is the link for that web service and in this link i have given the region name as london.
Note: You need to include SBJson library to your code.
At the end of that link i have appended address, if you append address- you need to give the region name (or) if you append latitude and longitude, you need to give coordinates and it will return the results accordingly.
And the code for calling google api will be like this
//Call the Google API
NSString *req = [NSString stringWithFormat:#"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%#", esc_addr];
NSLog(#"The get address is %#", req);
//Pass the string to the NSURL
NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL];
NSLog(#"The result is %#", result);
//Initialize the SBJSON Class
SBJSON *parser = [[SBJSON alloc] init];
NSError *error = nil;
//Get the resullts and stored in the address array
addressArray = [parser objectWithString:result error:&error];
//Get the latitude values for the given address
NSDictionary *dict = [[[addressArray valueForKey:#"results"] valueForKey:#"geometry"] valueForKey:#"location"];
self.latitudeValue = [[dict valueForKey:#"lat"] objectAtIndex:0];
self.longitudeValue = [[dict valueForKey:#"lng"] objectAtIndex:0];
NSLog(#"LAT : %#",self.latitudeValue);
NSLog(#"LONG : %#",self.longitudeValue);
I have an app which prompts the user to input an address. Is there a way to check whether or not the address is a valid address, either using Google's Maps or Places APIs or not? Any help would be appreciated. I know it's a vague question but I'm not really sure how to ask it any other way.
NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%#&output=csv",
[addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; // addressField is where you enter your address.
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSUTF8StringEncoding error:nil];
NSArray *listItems = [locationString componentsSeparatedByString:#","];
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:#"200"]) {
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
If address exists you will get coordinates in latitude and longitude. Hope this helps.
A fast way to kill 95% spam profiles was for my company to have a onboard list of us state names and zip codes. If zip code and state did not match, we peomted the user to check again.
Not foolproof at all, but if spammers are the problem, this might help.
I am trying to develop an travel application.I would like to submit the Airport code and get back the Country,City, along with the weather of that particular space.Is there an API out in the market that will help me in doing that???Or is there some other way I can do that?
Here's one for the city/country: http://airportcode.riobard.com/about
and this question has good info about weather: Weather API - Provides "About to..." Information?
Here's a sample piece of code that accepts the text from 'inputTextField' and outputs the location to 'outputLabel'
-(IBAction)getCity{
NSString *urlString = [NSString stringWithFormat:#"http://airportcode.riobard.com/airport/%#?fmt=json",self.inputTextField.text];
NSURL *url = [NSURL URLWithString:urlString];
NSString *response = [[NSString alloc] initWithContentsOfURL:url];
const char *convert = [response UTF8String];
NSString *responseString = [NSString stringWithUTF8String:convert];
NSDictionary *airport = [responseString JSONValue];
self.outputLabel.text=[airport objectForKey:#"location"];
}