Get latitude/longitude coordinates from a Google map using a marker

后端 未结 5 1790
梦如初夏
梦如初夏 2020-12-24 07:54

I just wondered if anyone knew of a simple script available that will do the following:

Load a google map in view, when clicked it displays a marker that will save t

5条回答
  •  隐瞒了意图╮
    2020-12-24 08:45

    the below code works well

    var latlng = new google.maps.LatLng(51.4975941, -0.0803232);
    var map = new google.maps.Map(document.getElementById('map'), {
        center: latlng,
        zoom: 11,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title: 'Set lat/lon values for this property',
        draggable: true
    });
    
    google.maps.event.addListener(marker, 'dragend', function (event) {
        document.getElementById("latbox").value = this.getPosition().lat();
        document.getElementById("lngbox").value = this.getPosition().lng();
    });
    

提交回复
热议问题