您好,我正在從w3schools學習Google Map API。我是JS新手,想將location.lat()
和location.lng()
分配給JavaScript變量。這是教程的複製代碼。我正在嘗試將值分配爲;如何將座標值分配給JS變量
var latid=location.lat();
但我認爲lat()
沒有返回。
我必須在數據庫中保存座標。如果這是錯誤的方法,那麼請告訴我如何在我的數據庫中保存lnglat
座標。
<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js?key=mykeyishidden&sensor=false"></script>
<script>
var map;
var myCenter=new google.maps.LatLng(51.508742,-0.120850);
function initialize() {
var mapProp = {
center:myCenter,
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
});
}
function placeMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map,
});
var infowindow = new google.maps.InfoWindow({
content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng()
});
infowindow.open(map,marker);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
</body>
</html>
這是一個客戶端腳本。沒有數據庫。 –
首先,請[避免使用W3Schools](http://w3fools.com)並傳播這個詞。主要原因是他們有很多不準確和過時的信息。其次,你想要保存什麼類型的數據庫? –
你在哪裏試圖將'location.lat()'賦值給一個變量 – tymeJV