[英]google maps javascript v3 api not working
我已經嘗試了所有可能的解決方案,但地圖並未顯示。 我的網絡視圖只是空白。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="theme.css">
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
<script type="text/javascript">
var map; " +
function initialize() {
var latitude = 0;
var longitude = 0;
if (window.android){
latitude = window.android.getLatitude();
longitude = window.android.getLongitude();
}
var myOptions = {
zoom: 20,
center: myLatLng
}
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
}
function centerAt(latitude, longitude){
myLatlng = new google.maps.LatLng(latitude,longitude);
map.panTo(myLatLng);
}
</script>
<title>Insert title here</title>
</head>
<body>
<div id="map_canvas" style="height: 100px; width=100px;">This is the map canvas</div>
<script type="text/javascript">initialize();</script>
</body>
</html>
我縮小到這一行:map = new google.maps.Map(document.getElementById('map_canvas'),myOptions);
當執行此行時,它將失敗。
任何幫助表示贊賞。
謝謝。
問候,德克斯特
除了centerAt()
函數之外,我看不到myLatLng
定義。 您需要將Google Maps LatLng
對象傳遞給myOptions
的center
屬性:
var myLatlng = new google.maps.LatLng(latitude, longitude);
var myOptions = {
zoom: 20,
center: myLatLng
}
...
還有一件我不明白的奇怪事情:
var map; " +
^ ^
我不好,提交了錯誤的代碼。 無論如何,這里的主要問題是連接。 因為我只是專注於代碼,所以花了我很長時間才意識到。
謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.