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 usin开发者_JAVA技巧g 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.
精彩评论