由於MarkerImage不見了,所以標記圖標的更新始終存在此問題。對於Marker.setIcon({url:「icon url」,anchor:....})的第一次調用工作正常,但是當我嘗試使用同一個對象字面值對同一個標記創建setIcon時,它會拋出這個除了在調試器:使用對象字面值更新標記上的圖標
<exception>: Af
message: "not a string"
name: "InvalidValueError"
stack: "Error↵ at Error (native)↵ at new Af (http://maps.googleapis.com/maps-api-v3/api/js/21/10/intl/de_ALL/main.js:26:682)↵ at Bf (http://maps.googleapis.com/maps-api-v3/api/js/21/10/intl/de_ALL/main.js:26:795)↵ at http://maps.googleapis.com/maps-api-v3/api/js/21/10/intl/de_ALL/main.js:28:60↵ at http://maps.googleapis.com/maps-api-v3/api/js/21/10/intl/de_ALL/main.js:28:181↵ at http://maps.googleapis.com/maps-api-v3/api/js/21/10/intl/de_ALL/main.js:28:401↵ at Zh.setIcon (http://maps.googleapis.com/maps-api-v3/api/js/21/10/intl/de_ALL/main.js:31:1423)↵ at $setIcon_6 (0.js:59576:15)↵ at $update_10 (0.js:98065:3)↵ at $liveTimerFireEvent (0.js:113687:7)"
__proto__: c
c: Object
anchor: U
origin: U
size: W
url: "resources/image.png"
__proto__: Object
this: undefined
由於其明顯的例外,我使用的版本21/10 劑量有人有一個問題,類似的東西? 我用一個字符串而不是一個對象來測試它的圖標,它的劑量是這樣的...
因爲人們投票我的問題之前,我甚至有機會說它不是普通的js ...在這裏未提取的例子...
/*
* declare map as a global variable
*/
var map;
/*
* use google maps api built-in mechanism to attach dom events
*/
google.maps.event.addDomListener(window, "load", function() {
/*
* create map
*/
var map = new google.maps.Map(document.getElementById("map_div"), {
center: new google.maps.LatLng(33.808678, -117.918921),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
/*
* create infowindow (which will be used by markers)
*/
var infoWindow = new google.maps.InfoWindow();
/*
* marker creater function (acts as a closure for html parameter)
*/
function createMarker(options, html) {
var marker = new google.maps.Marker(options);
if (html) {
google.maps.event.addListener(marker, "click", function() {
infoWindow.setContent(html);
infoWindow.open(options.map, this);
});
}
return marker;
}
/*
* add markers to map
*/
var marker0 = createMarker({
position: new google.maps.LatLng(33.808678, -117.918921),
map: map,
icon: { url : "http://1.bp.blogspot.com/_GZzKwf6g1o8/S6xwK6CSghI/AAAAAAAAA98/_iA3r4Ehclk/s1600/marker-green.png" }
}, "<h1>Marker 0</h1><p>This is the home marker.</p>");
var marker1 = createMarker({
position: new google.maps.LatLng(33.818038, -117.928492),
map: map
}, "<h1>Marker 1</h1><p>This is marker 1</p>");
var marker2 = createMarker({
position: new google.maps.LatLng(33.803333, -117.915278),
map: map
}, "<h1>Marker 2</h1><p>This is marker 2</p>");
setInterval(function(){ marker0.setIcon({ url : "http://1.bp.blogspot.com/_GZzKwf6g1o8/S6xwK6CSghI/AAAAAAAAA98/_iA3r4Ehclk/s1600/marker-green.png" }); alert("called");}, 3000);
});
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
<div id="map_div" style="height: 400px;"></div>
後您的javascript代碼,演示了你在做什麼 – duncan
嗯,我是其中規定的問題有點清晰: 劑量別人有一些類似的問題在更新標記帶有圖標對象的圖標? 我無法發佈代碼,因爲我使用gwt包裝器,並且是非常大的應用程序的一部分。但事情是代碼在Google從MarkerImage更改爲Icon(Plain js對象)之前完美地工作,現在它的工作也正常,但不是100%。 我不做任何特別的內部。 就像我在後期創建標記中所說的,並嘗試用對象更新圖標,我現在也添加了一個計劃js代碼,它會生成相同的異常... – user1257452
適用於我:http://jsfiddle.net/duncancumming/86oj3ppq /你是在哪裏創建'marker0'的地方,還是你用'marker0.setIcon'更新它的地方? – duncan