Flask-GoogleMaps
Flask-GoogleMaps copied to clipboard
Center map based on User's location?
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.
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.
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