2017-01-31 9 views

答えて

1

あなたは経度から場所アドレスの詳細を希望して、あなたは局所性を得るためにGMSReverseGeocodeを試すことができ緯度、小字、administrativeArea、国などの場合

-(NSString*)getLocalAddress:(CLLocationCoordinate2D)coor 
{ 
    [[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(coor.latitude, coor.longitude) completionHandler:^(GMSReverseGeocodeResponse* response, NSError* error) { 
     NSLog(@"reverse geocoding results:"); 
     for(GMSAddress* addressObj in [response results]) 
     { 
      NSLog(@"%@",[response results]); 

      NSLog(@"coordinate.latitude=%f", addressObj.coordinate.latitude); 
      NSLog(@"coordinate.longitude=%f", addressObj.coordinate.longitude); 
      NSLog(@"thoroughfare=%@", addressObj.thoroughfare); 
      NSLog(@"locality=%@", addressObj.locality); 
      NSLog(@"subLocality=%@", addressObj.subLocality); 
      NSLog(@"administrativeArea=%@", addressObj.administrativeArea); 
      NSLog(@"postalCode=%@", addressObj.postalCode); 
      NSLog(@"country=%@", addressObj.country); 
      NSLog(@"lines=%@", addressObj.lines); 
     } 
    }]; 
} 

それとも、グーグルマップから詳細を取得することができますapi's。

-(void)getGoogleAdrressFromLatLong : (CLLocationCoordinate2D)coor 
    { 
      NSError *error = nil; 
      NSString *lookUpString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",coor.latitude, coor.longitude]; 
      // OR 
      // NSString *lookupString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",latitude,longitude]; 

      lookUpString = [lookUpString stringByReplacingOccurrencesOfString:@" " withString:@"+"]; 
      NSData *jsonResponse = [NSData dataWithContentsOfURL:[NSURL URLWithString:lookUpString]]; 
      NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonResponse options:kNilOptions error:&error]; 
      NSLog(@"%@",jsonDict); 

      NSArray* jsonResults = [jsonDict objectForKey:@"results"]; 
      NSLog(@"%@",jsonResults); 

     } 
関連する問題