[英]Load map Lon & Lat to script inside html is not working
從數據庫到腳本以及加載到腳本的地圖緯度和經度值正常運行,但地圖未顯示
這是腳本
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var loc= document.getElementById('loc');
alert(loc.innerHTML);
var latlng = new google.maps.LatLng('+loc+');
var myOptions = {
zoom: 8,
center: latlng,
mapTypeControl: false,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
if (geocoder) {
geocoder.geocode( { }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);
var infowindow = new google.maps.InfoWindow(
{
size: new google.maps.Size(150,50)
});
var marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title:address
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
} else {
}
} else {
}
});
}
}
HTML
<div id="map_canvas" style="width: 270px; height: 267px;">
</div>
警報顯示值10.52722212213278、76.20814598432844
但地圖未加載
如果您知道這一點,請分享答案
取代這個
var latlng = new google.maps.LatLng("Lat", "Long");
通過
var loc= document.getElementById('loc'); //Remove This
var latlng = new google.maps.LatLng('+loc+'); //Remove This
如我的代碼所示,添加帶有兩個單獨坐標的線,即“ Lat”,“ Long”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.