Show My Location on Google Maps API v3

后端 未结 4 1900
清酒与你
清酒与你 2020-12-04 22:33

"My Location" in Google Maps javascript API

This question was asked over half a year ago. Has Google Maps API v3 updated to use the \"My Location\" button

4条回答
  •  萌比男神i
    2020-12-04 23:15

    No, but adding your own marker based on current location is easy:

    var myloc = new google.maps.Marker({
        clickable: false,
        icon: new google.maps.MarkerImage('//maps.gstatic.com/mapfiles/mobile/mobileimgs2.png',
                                                        new google.maps.Size(22,22),
                                                        new google.maps.Point(0,18),
                                                        new google.maps.Point(11,11)),
        shadow: null,
        zIndex: 999,
        map: // your google.maps.Map object
    });
    
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(pos) {
            var me = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
            myloc.setPosition(me);
        }, function(error) {
            // ...
        });
    }
    

提交回复
热议问题