<分区>
所以我正在寻找一种方法来将谷歌地图 API 中的纬度和经度传递到 PHP 文本字段。 到目前为止,我有以下代码,但我被卡住了,非常感谢任何帮助。
<!DOCTYPE html>
<html>
<head>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false">
</script>
<script>
function initialize()
{
var mapProp = {
center:new google.maps.LatLng(51.8978719,-8.471087399999988),
zoom:12,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap")
,mapProp);
citMarker=new google.maps.Marker({
position:new google.maps.LatLng(51.885403000000000000,-8.534554100000037000),
animation:google.maps.Animation.BOUNCE
});
var infowindow = new google.maps.InfoWindow({
content:'<b>Cork IT</b>'
});
infowindow.open(map,citMarker);
citMarker.setMap(map);
google.maps.event.addListener(citMarker, 'click', function() {
map.setZoom(15);
map.setCenter(citMarker.getPosition());
infowindow.open(map,citMarker);
});
google.maps.event.addListener(map, 'rightclick', function(event) {
placeMarker(event.latLng);
});
function placeMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map,
});
var lat = location.lat();
var long = location.lng();
window.location.href = "testmap.php?dlat=" + lat + "&dlong=" + long;
var infowindow = new google.maps.InfoWindow({
content: 'Latitude: ' + location.lat() +
'<br>Longitude: ' + location.lng()
});
infowindow.open(map,marker);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
<?php
function getLatLong() {
// Check if we have parameters dlat and dlong being passed to the script through the URL
if (isset($_GET["dlat"]) && isset($_GET["dlong"])) {
// Put the two words together with a space in the middle to form "hello world"
$lat = $_GET["dlat"];
$long = $_GET["dlong"];
// Print out some JavaScript with $hello stuck in there which will put "hello world" into the javascript.
echo $hello;
echo $lat;
echo $long;
}
}
?>
getLatLong();
Lat 1:<input type="text" size="20" maxlength="50" name="displayLat" value="<?php echo $lat; ?>"><br />
Long 1:<input type="text" size="20" maxlength="50" name="displayLong"><br />
</body>
</html>
到目前为止,它显示的是谷歌地图,当您右键单击 map 时,会弹出一个信息窗口,提供空间坐标, map 下方显示 2 个文本字段,我想做的是显示纬度当您右键单击 map 时,表格中会显示经度和经度。