flask-extensions / Flask-GoogleMaps

Easy way to add GoogleMaps to Flask applications. maintainer: @getcake
https://flask-googlemaps.com
MIT License
644 stars 195 forks source link

Center map based on User's location? #52

Open kaiofreitas opened 7 years ago

kaiofreitas commented 7 years ago

I've been using Flask-GoogleMaps to display some companies that are partnering with us.

I would be great if we had a way to center the map based on user's location. So then users could see easily all the markers around them.

For now, I'm using request.access_route to get user's IP/Location and then, set the lat and lng variables.

Wondering if it could be included in the next versions.

rochacbruno commented 7 years ago

That is a good idea and I know there is some JS way for doing that, we can include some option, will take a look.

rochacbruno commented 7 years ago

an example

 var map;

 function initialize() {
     var myLatlng1 = new google.maps.LatLng(53.65914, 0.072050);

     var mapOptions = {
         zoom: 10,
         center: myLatlng1,
         mapTypeId: google.maps.MapTypeId.ROADMAP
     };
     var map = new google.maps.Map(document.getElementById('map'),
     mapOptions);

     if (navigator.geolocation) {
         navigator.geolocation.getCurrentPosition(function (position) {
             initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
             map.setCenter(initialLocation);
         });
     }
 }
 initialize();

and also there is this docs

https://developers.google.com/maps/documentation/javascript/geolocation