正如您在以下代码中看到的那样,我正在从 MySQL 数据库中获取数据,但是当我想使用获取的“位置”来设置谷歌地图上标记的“位置”时,我遇到了困难。
<head>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxxxxxxxxx&sensor=true"></script>
<script>
$.getJSON('http://www.wawhost.com/appProject/fetchmarker.php?callback=?', function(data) {
for (var i = 0; i < data.length; i++) {
localStorage.loc = data[i].location;
}
});
</script>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882, 131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var marker = new google.maps.Marker({
position: 'new google.maps.LatLng(' + localStorage.loc + ')',
map: map,
title: 'Hello World!'
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
</body>
谢谢!