財產「標記」我有我的地圖div
容器總是在頁面上:谷歌地圖V3 - 遺漏的類型錯誤:無法讀取的不確定
<div id="map_canvas"></div>
起初我是想在AJAX來把這段DOM回調,但有麻煩,所以決定現在靜態。
我試圖從一個jQuery Ajax回調
...
complete: function(data) {
// build the map
$.getScript("http://maps.google.com/maps/api/js?v=3&libraries=geometry&sensor=false®ion=uk&async=2&callback=MapApiLoaded", function() {});
running = false;
if(running) return false;
running = true;
setMarkers();
flightPath.setMap(null); // Remove polyline
flightPathProgress.setMap(null); // Remove polyline
setTimeout(function() {
flightPath.setMap(map);
flightPathProgress.setMap(map);
flightPathProgress.setOptions({
strokeOpacity: 0
});
var progress = 0;
var intvl = setInterval(function(){
progress += 0.01;
if(progress > 1) {
clearInterval(intvl);
running = false;
} else {
}
// Calc progress
var progressLatLng = google.maps.geometry.spherical.interpolate(userlatlng, serverlatlng, progress);
// Update polyline
flightPathProgress.setOptions({
strokeOpacity: progress,
path: [userlatlng, progressLatLng]
});
}, 50);
}, 1000);
}
我也有以下的文件準備好功能
var map;
var serverlatlng;
var userlatlng;
var servermarker;
var usermarker;
var flightPath;
var flightPathProgress;
var running;
function MapApiLoaded() {
serverlatlng = new google.maps.LatLng(34.0625, -118.123);
userlatlng = new google.maps.LatLng(54.167, -4.48211);
var centerlatlng = new google.maps.LatLng(44.0835, -61.241055);
// Create the map
var myOptions = {
center: centerlatlng,
mapTypeId: google.maps.MapTypeId.TERRAIN,
panControl: false,
zoomControl: false,
streetViewControl: false,
mapTypeControl: false
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
// Centre map on user and server locations
var bounds = new google.maps.LatLngBounds();
bounds.extend(serverlatlng);
bounds.extend(userlatlng);
map.fitBounds(bounds);
// The grey outline path
flightPath = new google.maps.Polyline({
path: [userlatlng,serverlatlng],
strokeColor: "#666",
strokeOpacity: 0.5,
strokeWeight: 4,
geodesic: true,
zIndex: 1
});
// The red progress path
flightPathProgress = new google.maps.Polyline({
path: [userlatlng,userlatlng],
strokeColor: "#ff0000",
strokeOpacity: 0,
strokeWeight: 4,
geodesic: true,
zIndex: 2
});
}
function setMarkers() {
if(servermarker != undefined) servermarker.setMap(null); // Remove marker if exists
servermarker = new google.maps.Marker({
position: serverlatlng,
map: map,
title:"Server",
animation: google.maps.Animation.DROP,
icon: 'images/marker.png'
});
if(usermarker != undefined) usermarker.setMap(null); // Remove marker if exists
usermarker = new google.maps.Marker({
position: userlatlng,
map: map,
title:"User",
animation: google.maps.Animation.DROP,
icon: 'images/marker.png'
});
}
我得到錯誤信息是Uncaught TypeError: Cannot read property 'Marker' of undefined
之外初始化地圖。
完整的擴展消息是
Uncaught TypeError: Cannot read property 'Marker' of undefined
www.domain.co.uk/:345
setMarkers www.domain.co.uk/:345
$.ajax.complete www.domain.co.uk/:242
fire jquery.js:3064
self.fireWith jquery.js:3176
done jquery.js:8259
callback`
雖然這是怎麼回事?直到'getScript'運行並觸發回調才能完成任何操作。 – martincarlin87
你的調試器告訴你什麼? – geocodezip
已更新的問題與完整的錯誤消息 – martincarlin87