1

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

Irfan
  • 4,301
  • 6
  • 29
  • 46
jenis
  • 36
  • 3

1 Answers1

0

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=%@&center=%@,%@&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..