我有一个项目,它使用Google places使用关键字搜索特定类型的业务,以我用户的当前位置为中心。例如,假设我正在尝试查找离我的用户最近的“粉色兔兔”。
在某些情况下,我的用户所在的位置没有我的特定类型的企业使用Google Places API最大搜索半径(20 In,IIRC)。“没有粉红色的兔子靠近你”
有没有什么方法可以搜索最近的匹配业务,即使它超出了初始的最大搜索范围?“最近的粉色兔兔: 30英里外的亚利桑那州索梅敦”
Google Places是用于此二次搜索的正确API。
我可以使用哪些后备服务来查找离我的用户最近的“粉红兔兔”商店?
发布于 2015-03-24 17:24:48
嗯,有一个更大半径的地方搜索的范围。https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=AddYourOwnKeyHere。当前搜索覆盖搜索url中提供的纬度和经度500米的圆圈。其最大值为50000。不幸的是,Google Places API不会根据用户的当前位置对结果进行排序。您需要手动计算搜索结果中的地点位置与您当前位置之间的距离。
// Calculating the distance
float deltaLat = (currentLocation.lat - place.lat);
float deltaLng = (currentLocation.lng - place.lng);
float distanceInDegree = sqrtf(deltaLat * deltaLat + deltaLng * deltaLng);
float distanceInMeter = distanceInDegree * 4000;
printf("distanceInMeter = %f",distanceInMeter); 找出距离最短的地方。
https://stackoverflow.com/questions/29191411
复制相似问题