0

我正在开发一个谷歌地图插件(总有另一个空间吗?)我正在绘制我的用户将插入到他们的内容中的地图的预览。我能够绘制我开始绘制的所有内容、信息窗口中的自定义内容、设置位置(通过places.Autocomplete)等。让我无法理解的一件事是没有绘制自定义地图图标。

我的目标是在第一次加载时绘制默认图标,然后在它更改时更新它

我在控制台中没有收到任何 404 或错误,并且我检查了我的事件处理程序并且它们都在工作。谁能告诉我我在哪里误入歧途?

这是我到目前为止所拥有的:

//Initilize the map
google.maps.event.addDomListener(window, 'load', initialize);
function initialize(infowindow) {

    var init_center = new google.maps.LatLng(43.703793, -72.326187);
    mapOptions = {
      center: init_center,
      zoom: parseFloat(mapZoomReturn),
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      scrollwheel : false,
    };
    var input = document.getElementById('mapAddress');
    var autocomplete = new google.maps.places.Autocomplete(input);
    var infowindow = new google.maps.InfoWindow();

    //var marker = new google.maps.Marker({
    //  position: init_center,
    //  map: map, 
    //  icon: mapMarkerImageReturn  
    //});

    // Draw the map 
    map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
            // marker needs to be set after the map
    var marker = new google.maps.Marker({
        position: init_center,
        map: map, 
        icon: mapMarkerImageReturn  
    });     

    // Set up event listeners

    // Info window DOM->MAP
    google.maps.event.addDomListener(document.getElementById('mapInfoWindow'),
        'change', function() {
        mapInfoWindowReturn = escape(jQuery('#mapInfoWindow').val());
        // get the extra content from feild, by this time the place_changed even will have fired at least once, so we have these values
        infowindowPlace = get_info_bubble(locIcon, locName, locAddress, locPhone, locWeb, mapInfoWindowReturn); // returns formatted markup for info bubble
        infowindow.setContent(infowindowPlace);
    });

    // Marker dropdown selection DOM->MAP
    google.maps.event.addDomListener(document.getElementById('mapMarker'), 'change', update_maker);
    // Custom marker text field DOM->MAP
    google.maps.event.addDomListener(document.getElementById('mapMarkerImage'), 'change', update_maker );

    function update_maker(){
        //update the marker imge - (not working)
        markerImage = get_marker_image(); // returns URL as string
        marker.setIcon(markerImage);
        marker.setPosition(locPlace.geometry.location);
        marker.setMap(map);
    }

    google.maps.event.addListener(autocomplete, 'place_changed', function() {
        infowindowPlace = get_info_bubble(locIcon, locName, locAddress, locPhone, locWeb, mapInfoWindowReturn);
        infowindow.close();
        if (mapMarkerImageReturn !=='' || mapMarkerImageReturn !== false) marker.setVisible(false);
            input.className = '';
            locPlace = autocomplete.getPlace();
        if (!locPlace.geometry) {
        // Inform the user that the place was not found and return.
            input.className = 'notfound';
        return;
        }
        // If the place has a geometry, then present it on a map.
        if (locPlace.geometry.viewport) {
            map.fitBounds(locPlace.geometry.viewport);
            mapCurrCenter = map.getCenter();
        } else {
            map.setCenter(locPlace.geometry.location);
            map.setZoom(parseFloat(mapZoomReturn));
            mapCurrCenter = map.getCenter();
        }

        // Set the marker image (not working)
        markerImage = get_marker_image(); // returns URL as string
        marker.setIcon(markerImage);
        marker.setPosition(locPlace.geometry.location);
        marker.setMap(map);

        // get the location values for the info bubble 
        if (locPlace.address_components) {
            //console.log(locPlace.address_components);
            // Populate values for info bubble
            locName = locPlace.name;
            locIcon = locPlace.icon;
            locAddress = locPlace.formatted_address;
            locPhone    = locPlace.formatted_phone_number;
            locWeb = locPlace.website;
        }
        infowindowPlace = get_info_bubble(locIcon, locName, locAddress, locPhone, locWeb, mapInfoWindowReturn);
        infowindow.setContent(infowindowPlace);
        infowindow.open(map, marker);
    });
}
4

0 回答 0