地图上的链接不起作用

时间:2017-05-29 06:37:16

标签: javascript android google-maps google-maps-api-3

我有一个使用Google Maps v3 API的集成地图的应用。在地图中,我展示了一些标记,其中包含客户名称,地址和建立路线的链接。

点击后的链接应该转到Google地图的原生应用程序,但它没有响应。谷歌标记的其他链接也是如此,如加油站,企业等......

我附加了加载地图,书签,信息窗口以及应该打开谷歌地图的原生应用程序的方法。

< - 编辑---> 核心应用程序是html,css,javascript和jquery。它不是android或ios native。

函数initMap(){

    // Origin, could be latlng or ZipCode
    var pointOrigin = new google.maps.LatLng(itemsPosition[0].latitud, itemsPosition[0].longitud);

    var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 15,
        // Map
        center: pointOrigin
    });

    var infowindow = new google.maps.InfoWindow();

    marker = new google.maps.Marker({
        position: new google.maps.LatLng(itemsPosition[0].latitud, itemsPosition[0].longitud),
        icon: "http://labs.google.com/ridefinder/images/mm_20_blue.png",
        map: map
    });

    var marker, i;
    for (i = 0; i < items.length; i++) {
        marker = new google.maps.Marker({
            position: new google.maps.LatLng(items[i].latitud, items[i].longitud),
            icon: "http://labs.google.com/ridefinder/images/mm_20_red.png",
            animation: google.maps.Animation.BOUNCE,
            map: map
        });

        google.maps.event.addListener(marker, 'click', (function(marker, i) {
            return function() {
                marker.setAnimation(null);

                infowindow.setContent("<div id='content'><h4>" + items[i].name + "</h4>" + items[i].dir + "<a id='ruta' href='" + showMap(items[i].latitud + "," + items[i].longitud) + "'>Ver Ruta</a></div>");

                infowindow.open(map, marker);
            }
        })(marker, i));
    }

    // open  navigator or  native Maps App
    function openMaps(latitud, longitud) {
        window.open(showMap(latitud + "," + longitud), '_system');
    }

    // url changes according  to device
    showMap = function(q) {
        var device = navigator.userAgent;
        var q = q.replace(/\s/g, "+");

        var url = "http://maps.google.com?saddr=" + itemsPosition[0].latitud + ',' + itemsPosition[0].longitud + "&daddr=" + q;

        if (device.match(/Iphone/i) || device.match(/iPhone|iPad|iPod/i)) {
            url = 'http://maps.apple.com/maps?saddr=Current%20Location&daddr=' + q
        } else if (device.match(/Android/i)) {
            url = "geo:0,0?q=" + q;
        } else if (device.match(/Windows Phone/i)) {
            url = "maps:" + q;
        }

        return url;
    }

1 个答案:

答案 0 :(得分:1)

如果是android: -

您应该使用geo-URI创建一个Intent对象:

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); context.startActivity(intent);

相关问题