Zab*_*abs 18 javascript php google-maps google-maps-api-3
我只是想知道是否有人知道可用的简单脚本将执行以下操作:
在视图中加载谷歌地图,单击它时会显示一个标记,将lat和long值保存到变量?
有谁知道PHP中是否存在这样的东西?
提前致谢
Sal*_*n A 29
也许您正在寻找类似于此Latitude-Longitude Finder工具的东西.示例代码是是API v2.以下是使用Google Maps API v3修剪的代码版本:
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(a) {
console.log(a);
// bingo!
// a.latLng contains the co-ordinates where the marker was dropped
});
Run Code Online (Sandbox Code Playgroud)
说明:必须将draggable标记的属性设置为true.然后,您可以将回调函数挂钩到该标记的dragend事件; 新的坐标将传递给函数,您可以将它们分配给JavaScript变量或表单字段.
// add a click event handler to the map object
GEvent.addListener(map, "click", function(overlay, latLng)
{
// display the lat/lng in your form's lat/lng fields
document.getElementById("latFld").value = latLng.lat();
document.getElementById("lngFld").value = latLng.lng();
});
Run Code Online (Sandbox Code Playgroud)
我想当你得到lat-lng然后你可以放置标记.
查看Google maps API v.3.从活动页面:
google.maps.event.addListener(map, 'click', function(event) {
// use event.latLng to place a google.maps.Marker
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
54947 次 |
| 最近记录: |