我使用V3的谷歌地圖API,但是當我點擊地圖上我看到了以下錯誤消息上的標記:谷歌地圖V3 Infowindow.open錯誤
b.K is not a function (72 out of range 43)
這裏是我的代碼:
var markers = [];
var map;
var markerClusterer = null;
var load_ids = [];
var rectangle;
var infowindow = new google.maps.InfoWindow();
功能showAddress(xaddress,xzoom){
clearOverlays(); $("#div_item_list").html(""); $('#map_canvas2').gMap({ address: xaddress, zoom:xzoom, onComplete: function() { //marker from address geocoder = new google.maps.Geocoder(); geocoder.geocode({'address': xaddress}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.gMap('addMarker', { key: 'mainMarker', latitude: results[0].geometry.location.lat(), longitude: results[0].geometry.location.lng(), popup: true }); >map_search(results[0].geometry.location.lat(),results[0].geometry.location.lng()); map.data('gmap').gmap.setCenter(results[0].geometry.location); //clearOverlays(); } else { alert("Geocoder failed due to: " + status); } }); } }); return false;
}
功能提供clearOverlays(){
if (markers) { for (i in markers) { markers[i].setMap(null); } } if(markerClusterer){ markerClusterer.clearMarkers(); }
}
功能map_search(LAT,LON){
$("#div_item_list").html('<img src="images/loader.gif"/>'); $.ajax({ url: "search/map/find_item", type: "POST", dataType: "json", data: "lat="+lat+"&lon="+lon, success: function(msg){ if (msg.length > 0) { //add marker on gmap markers = []; $.each(msg, function(item) { load_ids.push(msg[item]['id_item']); html_data = '<b>' + msg[item]['code'] + ' ('+ msg[item]['case_transtype'] +')</b><br/>' + 'Address: ' + msg[item]['address_name']; var marker = createMarker(msg[item]['id_item'],markers,msg[item]['lat'],msg[item]['lon'],html_data); markers.push(marker); }); markerClusterer = new MarkerClusterer(map.data('gmap').gmap, markers); load_grid2(lat,lon); load_listener(); } else { $("#div_item_list").html("Empty"); } } });//end ajax
}
功能createMarker(OBJECT_ID,標誌,緯度,經度,html_data){
var _gicon = { image: 'images/item.png', iconSize: new google.maps.Size(32, 32), iconAnchor: new google.maps.Point(12, 46) }; gicon = new google.maps.MarkerImage(_gicon.image, _gicon.iconSize, null, _gicon.iconAnchor); var latLng = new google.maps.LatLng(lat,lng); var marker = new google.maps.Marker({ 'position': latLng, 'icon': gicon }); google.maps.event.addListener(marker, 'click', function(){ infowindow.close(); infowindow.setContent(html_data); infowindow.open(map,marker); //change screen $('#point_show_'+object_id).addClass("ui-state-hover"); $('#point_show_'+object_id).trigger("focus"); }); return marker;}
當腳本infowindow.open(map,marker);
執行
,例如,你可以檢查錯誤想出了http://cremp.solusi247.com/eways/en/search/map/index/
,在地址文本框中使用關鍵字「利雅得」進行搜索。並點擊1房屋圖標。
我看不到你在哪裏創建「infowindow」 – 2012-01-31 11:13:36
infowindow,map是一個全局變量。 – 2012-01-31 11:43:31
請顯示您的完整代碼或創建一個小提琴。 – 2012-01-31 12:09:02