如何仅使用位置经度和纬度从 google 地点 api 获取地点详细信息
how to get a place detail from google place api , by using only location longitude and latitude
我正在实施 google 地图和 google 地点,我想从位置经度和纬度获取地点详细信息。知道如何获得吗?在此先感谢您的帮助
如果您想从经度和纬度获取详细的地点地址,那么您可以尝试使用 GMSReverseGeocode 来获取地区、子地区、行政区域、国家等。
-(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);
}
}];
}
或者您可以从 google 地图 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);
}
我正在实施 google 地图和 google 地点,我想从位置经度和纬度获取地点详细信息。知道如何获得吗?在此先感谢您的帮助
如果您想从经度和纬度获取详细的地点地址,那么您可以尝试使用 GMSReverseGeocode 来获取地区、子地区、行政区域、国家等。
-(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);
}
}];
}
或者您可以从 google 地图 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);
}