In my iOS app, I'm opening google map app from inside the code. I can open it but when it launches, I can only see the coordinate of the location. Does it make any sense to anyone ? It must be location name or coordinate with location name. Anybody know how to display name ?
I am using this code:
NSString *url = [NSString stringWithFormat: @"comgooglemaps://maps.google.com/?q=%f,%f", lat, lng];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
Help will be appreciated.
Thank you
use this below function for getting address for lat long..
-(NSString *)getAddressFromLat:(NSString *)Lati Long:(NSString *)Longi {
NSString *strUrl = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%@,%@&sensor=true",Lati,Longi];
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:strUrl]];
NSError *e = nil;
NSMutableArray *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&e];
return [[[json valueForKey:@"results"] objectAtIndex:0]valueForKey:@"formatted_address"];
}
pass this function below code:
NSString *strAdd =[self getAddressFromLat:LATITUDE Long:LONGITUDE];
if ([[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]]) {
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:[NSString stringWithFormat:@"comgooglemaps://?q=%@¢er=%@,%@&views=satellite,traffic&zoom=15",[strAdd stringByReplacingOccurrencesOfString:@" " withString:@"+"],LATITUDE,LONGITUDE]];
} else {
NSLog(@"Can't use comgooglemaps://");
}
Above this code great work for me. try this . this will work great..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.