Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript google maps API3基于用户选择绘制自定义地图图标_Javascript_Google Maps Api 3 - Fatal编程技术网

Javascript google maps API3基于用户选择绘制自定义地图图标

Javascript google maps API3基于用户选择绘制自定义地图图标,javascript,google-maps-api-3,Javascript,Google Maps Api 3,我正在开发一个谷歌地图插件(总有空间再安装一个吧?)。我能画出我要画的所有东西,信息窗口中的自定义内容,设置位置(通过places.Autocomplete)等等。唯一让我感到困惑的是自定义地图图标没有被画出来 我的目标是在第一次加载时绘制默认图标,然后在更改时更新它 我在控制台中没有收到任何404或错误,我已经检查了我的事件处理程序,它们都正常工作。有人能告诉我我误入歧途的地方吗 以下是我到目前为止的情况: //Initilize the map google.maps.event.addDo

我正在开发一个谷歌地图插件(总有空间再安装一个吧?)。我能画出我要画的所有东西,信息窗口中的自定义内容,设置位置(通过
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);
    });
}

什么是“mapMarkerImageReturn”,默认图标是否正确显示?您的函数是否返回正确的URL?尝试删除
marker.setMap(map)
,如果图标已在地图上,则只需更新图标,并将
mapMarkerImageReturn
作为字符串显示当前图标的值,并且它只是fine@koala_devdefult图标不仅仅显示信息窗口。拿出
marker.setMap(map)
似乎没有任何区别。我认为构建信息窗口的方式和标记的设置方式存在冲突。请尝试更改标记初始化和映射构造函数的顺序,即在创建映射后创建标记