我有一个问题......我将我的纬度和经度保存在.xml文件中
PHP:
$lat=$_POST['lati'];
$long=$_POST['lng'];
我试图在谷歌地图上显示用户的位置。我显示我的地图的代码是:
<!--GOOGLE MAPS LIBRARY:-->
<script>
//LOCATION SCRIPT HERE
function initialize() {
var lat_place=document.getElementById("lati");
var lng_place=document.getElementById("lng");
var myLatlng = new google.maps.LatLng((document.getElementById("lati")), (document.getElementById("lng")));
var myOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;
//LOCATION SCRIPT ENDS HERE
</script>
您尚未分配值正确的代码应为:
function initialize() {
var lat_place=document.getElementById("lati").value;
var lng_place=document.getElementById("lng").value;
var myLatlng = new google.maps.LatLng(lat_place, lng_place);
var myOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}