Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show My Location on Google Maps API v3

"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 found on http://maps.google.com?

My Location is the control between the Street View man and the gamepad-looking controls.

If Google Maps API doesn't provide My Location then do I need to write my own HTML5 geolocation feature using navigator.gelocation then create my own control on Google Maps?

like image 945
hobbes3 Avatar asked Feb 04 '12 17:02

hobbes3


People also ask

Can we use google location API for free?

As mentioned, you won't be charged for your Google Maps API usage until you turn on auto-billing. The free trial limits you to $300 in credit over 90 days. API users also get $200 of credit per month toward API requests, equal to 100,000 static map requests or around 28,000 dynamic map requests per month.


1 Answers

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) {
        // ...
    });
}
like image 163
josh3736 Avatar answered Oct 28 '22 05:10

josh3736