如何不断从Google Maps Android中的当前位置检测附近的标记位置?

如何不断从Google Maps Android中的当前位置检测附近的标记位置?,第1张

如何不断从Google Maps Android中的当前位置检测附近的标记位置?

简短答案

location.distanceTo(anotherLocation)

我建议在setupMap中添加其他侦听器,以简单的方式获取所有位置更改。

mMap.setMyLocationEnabled(true);mMap.setonMyLocationChangeListener(this);

然后,在此侦听器中,您只需在当前位置和目标之间进行测量即可。距离,以米为单位。

@Overridepublic void onMyLocationChange(Location location) {    Location target = new Location("target");    for(LatLng point : new LatLng[]{POINTA, POINTB, POINTC, POINTD}) {        target.setLatitude(point.latitude);        target.setLongitude(point.longitude);        if(location.distanceTo(target) < METERS_100) { // bingo!        }    }}

当然,你应该做活动

implements GoogleMap.OnMyLocationChangeListener



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5487074.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-12
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存