![](/img/trans.png)
[英]Use google maps computeDistanceBetween to get the closest location returns NaN
[英]Google Maps API (3) computeDistanceBetween returns NaN
我们正在使用Google Maps API在我们的网站上显示所有诊所的列表,而我正在编写“显示我附近的所有诊所”功能。 一切工作正常,使用几何库中的Google Maps Circle调用在地图上绘制了一个圆。
我们要返回该圈子内所有诊所的列表。 我们的诊所通过$.get();
加载$.get();
从单独的.js文件调用。 我一直在搞砸google.maps.geometry.spherical.computeDistanceBetween(pointA, pointB);
功能测试如果每个诊所落在圆,其中内pointB
是圆的中心和pointA
是这两者都是经由限定的clinic-的位置new google.maps.LatLng(clinic.lat, clinic.long));
。
ComputeDistanceBetween
会继续为每个诊所返回NaN
。 由于一些敏感性问题,我无法共享正在使用的确切代码,但是我在这里修改了Google Maps API小提琴以进行标记聚类,因为我们还使用标记聚类,纬度/经度负载与我们类似。
我已经检查了这篇文章 ,但对我来说没有用。
您的代码中有错字。 locations[x].long
不存在,应该是locations[x].lng
因此您的功能应为:
var mylocation = new google.maps.LatLng(locations[0].lat, locations[0].lng);
console.log(mylocation);
var marker_lat_lng = new google.maps.LatLng(locations[2].lat, locations[2].lng);
console.log(marker_lat_lng);
var distance_from_location = google.maps.geometry.spherical.computeDistanceBetween(mylocation, marker_lat_lng);
document.getElementById('feedback').innerHTML = distance_from_location;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.