【问题标题】:i would want to get google directions from my location to the marker that gets clicked on the map我想从我的位置获取谷歌路线到地图上点击的标记
【发布时间】:2013-03-20 17:40:09
【问题描述】:
src="http://www.google.com/jsapi?key=AIzaSyBkplC2WJePplXwHeSeiYCPh1QtHrLE_Oo"
if (navigator.geolocation) {enableHighAccuracy: true,
    navigator.geolocation.watchPosition(function(position){
        var latitude = position.coords.latitude;
        var longitude = position.coords.longitude;
        var coords = new google.maps.LatLng(latitude, longitude);
        var mapOptions = {
            zoom: 13,
            center: coords,
            mapTypeControl: true,
            navigationControlOptions: {
                style: google.maps.NavigationControlStyle.SMALL
            },
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("mapContainer"), mapOptions);
        //mylocation as a marker on the map
        var marker1 = new google.maps.Marker({
            position: coords,
            draggable: false,
            map: map,
            title: "Your current location!"
        });
        //the circle radius on the marker 
        var myCity = new google.maps.Circle({
            center:coords,
            radius:2000,
            strokeColor:"#0000FF",
            strokeOpacity:0.5,
            strokeWeight:1,
            fillColor:"#0000FF",
            fillOpacity:0.1
        });

        myCity.setMap(map);
    });
    enableHighAccuracy: true;
}else {
    alert("Geolocation API is not supported in your browser.");
}

【问题讨论】:

  • 你试过什么?你这样做有什么问题?假设问题的标题是您想要做的。
  • 我想要一条折线从我的位置显示到我点击地图上的标记(尚未添加标记)

标签: javascript google-maps


【解决方案1】:

这个工作示例HERE 可能会回答您的问题。尝试点击给定地图上的任何标记,它会为您提供当前位置的方向。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-23
    • 2017-12-03
    • 1970-01-01
    • 2017-08-08
    • 1970-01-01
    • 1970-01-01
    • 2016-09-07
    • 2014-10-03
    相关资源
    最近更新 更多