Google maps v3 draggable marker

前端 未结 4 509
忘了有多久
忘了有多久 2021-01-29 23:37

I\'m new in google maps, and I\'m trying to learn it.

marker = new google.maps.Marker(
{
     map:map,
     draggable:tru         


        
4条回答
  •  孤独总比滥情好
    2021-01-30 00:02

    /**
     *Receiving the value of text box and type done conversion by Number() 
     */
    var latitude = Number(document.getElementById("la").value);
    var longitude = Number(document.getElementById("lo").value);
    
    function initMap() {
      /**
       *Passing the value of variable received from text box
       **/
      var uluru = {
        lat: latitude,
        lng: longitude
      };
      var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 7,
        center: uluru
      });
      marker = new google.maps.Marker({
        map: map,
        draggable: true,
        animation: google.maps.Animation.DROP,
        position: uluru
      });
      google.maps.event.addListener(marker, 'dragend',
        function(marker) {
          currentLatitude = marker.position.lat();
          currentLongitude = marker.position.lng();
          $("#la").val(currentLatitude);
          $("#lo").val(currentLongitude);
        }
      );
    }
    #map {
      height: 400px;
      width: 100%;
    }
    
    
    Latitude Longitude
    提交回复
热议问题