computeDistanceBetween不起作用

时间:2015-12-28 12:41:19

标签: javascript google-maps google-maps-api-3

我有以下代码:

function checkDistance(circle, beacon) {
            navigator.geolocation.getCurrentPosition(function(position) {
              pos = {
                lat: position.coords.latitude,
                lng: position.coords.longitude
              };
              document.getElementById('latField').value = pos.lat;
              document.getElementById('lngField').value = pos.lng;            
              map.setCenter(pos);
              userCircle.setCenter(pos);
              modalmap.setCenter(pos);
              console.log("testend");
              var centercircle = circle.getCenter();
              console.log(centercircle);
              var distance = google.maps.geometry.spherical.computeDistanceBetween(centercircle, pos);
              console.log(distance);
            var radius = circle.getRadius();
            console.log(radius);
            if (distance <= radius) {
                circle.addListener('click', function() {
                    post('claimcreds.php', {id: beacon.id, cid: <?php echo $uid ?>, uid: beacon.uid, lat: pos.lat, lng: pos.lng, claimattempt: "true"});
            });
        }
            })
        }

poscentercircle似乎都正确地返回google.maps.LatLng,但google.maps.geometry.spherical.computeDistanceBetween似乎并不想返回任何内容。我在控制台中没有收到任何错误,但console.log(distance);声明中没有任何错误。

任何人都知道为什么?

1 个答案:

答案 0 :(得分:1)

我不认为你可能得到例如private DataReadRequest queryFitnessData() { Calendar cal = Calendar.getInstance(); Date now = new Date(); cal.setTime(now); long endTime = cal.getTimeInMillis(); cal.add(Calendar.WEEK_OF_YEAR, -1); long startTime = cal.getTimeInMillis(); SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); Log.i(TAG, "Range Start: " + dateFormat.format(startTime)); Log.i(TAG, "Range End: " + dateFormat.format(endTime)); DataReadRequest readRequest = new DataReadRequest.Builder() .aggregate(DataType.TYPE_CALORIES_EXPENDED,DataType.AGGREGATE_CALORIES_EXPENDED) .bucketByTime(1, TimeUnit.DAYS) .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS) .build(); return readRequest; } 的输出,但没有错误。

centerCircle期望作为参数computeDistanceBetween - 实例,但您通过google.maps.LatLng提供pos - 文字

使用:

LatLng