yii2-google-maps-library icon indicating copy to clipboard operation
yii2-google-maps-library copied to clipboard

How to get current location for direction to destination?

Open kongoon opened this issue 8 years ago • 4 comments

How to get current location for direction to destination?

kongoon avatar Sep 13 '16 19:09 kongoon

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

tonydspaniard avatar Oct 11 '16 10:10 tonydspaniard

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());
    }`

kongoon avatar Dec 05 '16 06:12 kongoon

Same question as well

YB1010 avatar Apr 01 '19 14:04 YB1010

@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) <---)

tonydspaniard avatar Apr 14 '19 16:04 tonydspaniard