简体   繁体   English

Javascript Google Maps更改图标

[英]Javascript Google Maps Changing Icons

I have been playing with Google maps I had it working but when I tried to change the Icons to Blue I lost some of the information in my pop up windows. 我一直在使用Google地图,但可以正常使用,但是当我尝试将图标更改为蓝色时,我在弹出窗口中丢失了一些信息。

The first windows that opens is all correct but the second click on windows opens but the only thing the is correct is the point information the Lat & Lng if I remove the couston Icon back to the default it all works. 打开的第一个窗口都是正确的,但是第二个打开的窗口是打开的,但是唯一正确的是如果我将couston Icon移回默认值,则点和纬度的点信息就可以了。 i found the information on a site and tried to copy it into my script. 我在网站上找到了该信息,并试图将其复制到我的脚本中。 I am just learning javascript and I am not sure where I when wrong. 我只是在学习javascript,所以我不确定在哪里出错。

The datetime alt speed and course are all ok on the frist window but fail on the click on window, the icons are now blue, if I remove the customIcons[call] from the statement var marker = createMarker(point,customIcons[call]); 在第一个窗口上,日期时间的高低速度和路线都可以,但是在单击窗口时失败,如果我从语句var marker = createMarker(point,customIcons [call])中删除customIcons [call],图标现在变成蓝色。 ; and replace it with datetime is seems to work. 并将其替换为datetime似乎可行。 I thank all for having a look if there is anything that you think may help please advise. 我感谢所有人查看您是否认为有什么帮助,请告知。

My Script..... 我的剧本...

function load() {
    if (GBrowserIsCompatible()) {

        // Get map (Version 2)
        var map = new GMap2(document.getElementById("map"));
        map.setUIToDefault();
        // Default user interface
        var icon = new GIcon();
        icon.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
        icon.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
        icon.iconSize = new GSize(12, 20);
        icon.shadowSize = new GSize(22, 20);
        icon.iconAnchor = new GPoint(6, 20);
        icon.infoWindowAnchor = new GPoint(5, 1);

        var customIcons = [];
        customIcons["VE9SC-9"] = icon;

        // Get course
        GDownloadUrl("http://guardian.no-ip.org/track/phpsqlajax_genxml_track_25.php",
        function(data) {
            var xml = GXml.parse(data);
            var markers =
            xml.documentElement.getElementsByTagName("marker");
            var points = new Array(0);
            // For polyline
            // Loop through the markers
            for (var i = 0; i < markers.length; i++) {
                var datetime = markers[i].getAttribute("datetime");
                var speed = markers[i].getAttribute("speed");
                var course = markers[i].getAttribute("course");
                var alt = markers[i].getAttribute("alt");
                var call = markers[i].getAttribute("call");
                var point =
                new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                parseFloat(markers[i].getAttribute("lng")));
                points[i] =
                new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                parseFloat(markers[i].getAttribute("lng")));
                var marker = createMarker(point, customIcons[call]);
                map.addOverlay(marker);
            }
            // End loop
            // Polyline
            var polyline = new GPolyline(points, "#0066cc", 2);
            map.addOverlay(polyline);
            // Set map centre (to last point), zoom level
            map.setCenter(point, 13);
            // InfoWindow HTML (last marker)
            var html = "";
            html += "<div id=\"infobox\">";
            html += "VE9SC-9";
            html += "<br />This is my last position on";
            html += "<br />" + datetime;
            html += " UTC";
            html += "<br />" + point;
            html += "<br />Aluitude ";
            html += +alt;
            html += " Feet ";
            html += "<br />" + speed;
            html += " MPH  Last Recorded Speed";
            html += "<br />" + course;
            html += " deg Last Recorded Course";
            html += "<br />ve9sc@rogers.com";
            html += "<br /><a href=\"/index.html\">ve9sc.no-ip.org</a></div>";
            html += "<br />Updated Via MySql PHP.";
            html += "</div>";
            map.openInfoWindowHtml(point, html);
        });
    }
}

// General markers
function createMarker(point, datetime) {
    var marker = new GMarker(point, datetime);

    var html = "";
    html += "<div id=\"infobox\">";
    html += "VE9SC-9";
    html += "<br />This is my position on";
    html += "<br />" + datetime;
    html += " UTC";
    html += "<br />" + point;
    html += "<br />Aluitude ";
    html += +alt;
    html += " Feet ";
    html += "<br />" + speed;
    html += " MPH  Last Recorded Speed";
    html += "<br />" + course;
    html += " deg Last Recorded Course";
    html += "<br />ve9sc@rogers.com";
    html += "<br /><a href=\"/index.html\">ve9sc.no-ip.org</a></div>";
    html += "<br />Updated Via MySql PHP.";
    html += "</div>";

    GEvent.addListener(marker, 'click',
    function() {
        marker.openInfoWindowHtml(html);
    });
    return marker;
}

It looks like you are using V2 of Google Map API (which kind of old). 看来您使用的是Google Map API的V2(较旧的版本)。 In this version the 2nd argument that you try to pass to GMarker should be an GMarkerOptions not an GIcon (assume API Version 2.5+) 在此版本中,您尝试传递给GMarker的第二个参数应该是GMarkerOptions而不是GIcon (假定API版本为2.5+)

From your code I think you are trying to pass GIcon object from customIcons[] in which is incorrect. 从您的代码中,我认为您尝试customIcons[]正确的customIcons[]传递GIcon对象。 I think you should inspect the datetime object here to make sure it's an GmarkerOptions not GIcon 我认为您应该在此处检查datetime对象,以确保它是GmarkerOptions而不是GIcon

var marker = new GMarker(point, datetime);

http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GMarker http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GMarker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM