【发布时间】:2023-03-15 05:50:01
【问题描述】:
我是地理位置的新手,我正在使用 PHP。我想在我的网站上获得一张地图,我网站上的一个人知道他的确切位置。他还应该能够像在 swiggy.com 中那样更改他在地图上的位置
【问题讨论】:
-
请发布代码,显示您到目前为止所尝试的内容。 How to Ask
标签: php google-maps geolocation
我是地理位置的新手,我正在使用 PHP。我想在我的网站上获得一张地图,我网站上的一个人知道他的确切位置。他还应该能够像在 swiggy.com 中那样更改他在地图上的位置
【问题讨论】:
标签: php google-maps geolocation
好的,我假设您已经阅读了 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;
});
【讨论】: