yii2-google-maps-library
yii2-google-maps-library copied to clipboard
How to get current location for direction to destination?
How to get current location for direction to destination?
There are many ways to do it:
- from user's browser (he will need to grant you permission)
- via the IP (I recommend MaxMind GeoIp)
- Ask the user for the address and then use Reverse Lookup using Google API
- Ask the user for the address and request GeoNames
i found code from Google Maps but how to add to this package? `if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
map.setCenter(pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}`
Same question as well
@kongoon that code can simply be appended by using https://github.com/2amigos/yii2-google-maps-library/blob/master/Map.php#L361
Make sure you give a name to the map and recall it when you append that code (map.setCenter(pos) <---
)