如何使用谷歌地图API中的jquery计算地理围栏半径

时间:2016-08-04 05:09:30

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

我想使用jquery计算地理围栏中2个标记之间的距离,我必须将距离限制为5 km。 如果我得到纬度和经度,如何使用jquery做到这一点。 我在地图上放置标记的代码如下:

function addPoint(event) { //alert(document.getElementById("<%= Checkbox_Polygon.ClientID %>").checked);
    if (document.getElementById("chkDrawPolyGon").checked) {
      $('input[type=radio]').change(function() {
        clearMarkerData();
      })

      if (markers.length > 19) {
        alert("Maximum 20 points per poygon only");
      } else {
        path.insertAt(path.length, event.latLng);


        //alert(event.latLng);
        //alert(path.length);
        //alert(path.getLength());
        var marker = new google.maps.Marker({
          position: event.latLng,
          map: map,
          draggable: true
        });
        //alert(marker.getPosition());
        markers.push(marker);

        marker.setTitle("#" + path.length);
        //to get Position of marker
        alert(markers[0].position.lat() + ',' + markers[0].position.lng());

        google.maps.event.addListener(marker, 'click', function() {
          if (document.getElementById("chkDrawPolyGon").checked) {
            marker.setMap(null);
            for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
            markers.splice(i, 1);
            path.removeAt(i);
            updatemarkerdata();
          }
        });
        google.maps.event.addListener(marker, 'dragend', function() {
          if (document.getElementById("chkDrawPolyGon").checked) {
            for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
            path.setAt(i, marker.getPosition());
            updatemarkerdata();
          }

        });

        updatemarkerdata();
        //alert(markerdata);
        getMarkerData();
      }
    }

I have markers here.. in this 1)i want to calculate distance between 2 marker. 2)Calucate radius if it is more than 3 points.the radius should be less than 5 kms

With 3 markers

0 个答案:

没有答案