我正在实施谷歌地图和谷歌地方,我想从位置经度和纬度获取地方细节。知道如何获得?在此先感谢您的帮助
答案 0 :(得分:1)
如果您想要从经度和纬度放置地址详细信息,那么您可以尝试使用GMSReverseGeocode来获取地点,subLocality,administrativeArea,country等。
-(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获取详细信息。
-(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);
}