MrB*_*yte 5 android location google-maps coordinates
我需要在我的应用程序中检查一下,确定给定的坐标是否在Google Maps中.
Google Maps API中是否有任何可以帮助我的功能?
提前致谢!
Sea*_*eau 15
据我所知,使用Google Maps API无法做到这一点.
我认为最好的办法是使用人群来源的数据集,如OpenStreetMap(OSM).
您需要设置自己的空间数据库(例如,PostGIS)并将OSM数据导入数据库.
然后,您将创建服务器端API(托管在诸如Tomcat或Glassfish之类的Web服务器中)以接收移动电话的当前位置,缓冲具有特定半径的位置以提供圆形多边形,并执行空间查询通过PostGIS确定缓冲区是否与任何道路相交(例如,标记为"highway = primary"或"highway = secondary"的方式,具体取决于您要包含的道路类型 - 请参阅此站点),并返回true或false回应电话.
编辑2015年8月
现在有在方法Android的地图-utils的库叫PolyUtil.isLocationOnPath(),将允许您将Android应用程序本身做这种类型的计算,假设你有一组点组成的道路(或任何其他线).
这是代码在库中的样子:
/**
* Computes whether the given point lies on or near a polyline, within a specified
* tolerance in meters. The polyline is composed of great circle segments if geodesic
* is true, and of Rhumb segments otherwise. The polyline is not closed -- the closing
* segment between the first point and the last point is not included.
*/
public static boolean isLocationOnPath(LatLng point, List<LatLng> polyline,
boolean geodesic, double tolerance) {
return isLocationOnEdgeOrPath(point, polyline, false, geodesic, tolerance);
}
Run Code Online (Sandbox Code Playgroud)
要使用此库,您需要将库添加到build.gradle:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.4+'
}
Run Code Online (Sandbox Code Playgroud)
然后,当你有你的观点和路径时,你需要将你的纬度/长度转换为LatLng对象(具体地说,分别是a LatLng point和List<LatLng> line),然后在你的代码调用中:
double tolerance = 10; // meters
boolean isLocationOnPath = PolyUtil.isLocationOnPath(point, line, true, tolerance);
Run Code Online (Sandbox Code Playgroud)
...看你的点是否在你的线的10米范围内.
有关如何使用它的详细信息,请参阅此库的" 入门指南".