如何通过仅使用位置经度和纬度从google place api获取地点详细信息

时间:2021-03-06 23:28:53

i am implementing google map and google place, i want to get place detail from location longitude and latitude. Any idea how to get ?. Thanks in advance for help

我正在实施谷歌地图和谷歌的地方,我想从位置经度和纬度获得地方细节。知道如何获得?在此先感谢您的帮助

1 个解决方案

#1


1  

If you want place address details from longitude and latitude then you can try GMSReverseGeocode to get locality, subLocality, administrativeArea, country etc.

如果你想从经度和纬度放置地址详细信息,那么你可以尝试GMSReverseGeocode来获取locality,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);
        }
    }];
}

Or you can get details from google map api's.

或者您可以从谷歌地图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);

        }

#1


1  

If you want place address details from longitude and latitude then you can try GMSReverseGeocode to get locality, subLocality, administrativeArea, country etc.

如果你想从经度和纬度放置地址详细信息,那么你可以尝试GMSReverseGeocode来获取locality,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);
        }
    }];
}

Or you can get details from google map api's.

或者您可以从谷歌地图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);

        }