Getting nearby localities from lat long using Google place API

こ雲淡風輕ζ 提交于 2019-12-24 03:51:07

问题


I'm using google place API i.e

https://maps.googleapis.com/maps/api/place/search/json?location=33.7167,73.0667&radius=500&type=funeral_home&sensor=false&key=AIzaSyDN1QX-gWUR-mIYo_D21PNFLHHpNQkIkGU

Above link gives me all the nearby locations of particular type. i.e types=food. now i will get all the cafes and restaurants nearby with their respective addresses. Is there anyway that can give me only areas or localities nearby my coordinates (lat, long)? Thanks in advance.


回答1:


I had a similar usecase too. I did not have a way to do it using google maps api. But, you can try getting geometry (lat, lng) from Autocomplete getPlaces() and use geonames.org API to get nearby sublocalities giving lat, lng and radius

http://api.geonames.org/findNearbyPlaceNameJSON?lat=13.041703&lng=80.251943&radius=5&username=demo

This worked for me :-)




回答2:


Arun if you can give the latitude and longitude value in

 //MAP

    MKCoordinateRegion region;

    CLLocationCoordinate2D coordinate;        

    //if you want to use the GET for getting response for MAP from that URL,you can use this

    coordinate.latitude = [[[Arrresult objectAtIndex:i]objectForKey:@"latitude"]doubleValue];
    coordinate.longitude =[[[Arrresult objectAtIndex:i]objectForKey:@"longitude"]doubleValue] ;

    //or if you want to see the exact or nearest location just give like this 
    coordinate.latitude = @"33.7167";
    coordinate.longitude =@"73.0667";

    region.center = coordinate;

    MKCoordinateSpan span;
    span.latitudeDelta = 0.2;
    span.longitudeDelta = 0.2;
    region.span = span;
    myannotation *annotation = [[myannotation alloc]init];
    annotation.coordinate = coordinate;
    [annotation setTitles:areastring :countrystring];

    [map setRegion:region animated:YES];
    [map addAnnotation:annotation];


来源:https://stackoverflow.com/questions/21830321/getting-nearby-localities-from-lat-long-using-google-place-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!