如何使用谷歌地图选择我的地理位置

问题描述:

我是新来的地理位置,我使用PHP。我想在我的网站上获得一张地图,网站上的某个人知道他的确切位置。他也应该能够像在swiggy.com那样改变他在地图上的位置如何使用谷歌地图选择我的地理位置

+1

请发布代码,显示您迄今尝试过的代码。 [如何问](http://*.com/help/how-to-ask) –

好的,我会假设你已经阅读过Google Map API文档。谷歌搜索你问应该在这里开车你:

https://developers.google.com/maps/articles/geolocation

我要什么告诉你是如何添加拖动的标记。

var map = new google.maps.Map([...]) 
    //After using geolocation and getting the user coordinates 

    var marker = new google.maps.Marker({ 
    //Note this variable contains the previously created LatLng Object 
    //with the user position 
    position: userPosLatLng, 

    //Important so the user can realocate 
    draggable: true, 

    map: map, 
    title: 'You're here' 
    }); 

想要在用户停止拖动标记时更新用户坐标吗?

在这里你做到了。在前面的行之后添加此事件监听器:

google.maps.event.addListener(marker, 'dragend', function(event) { 
    userPosLatLng = event.latLng; 
});