Angular map with directions and geolocation


#1

Hello evreybody,

I tried to look everywhere for this but i could not find anything relevant so far.
I will like to display a map in my ionic app that will get user location (point A) and will display the directions to a preset adress (Point B)
This is what i have so far.

Thank you!


#2

Go to the source!
Full of examples thereā€¦

Another example


#3

Thank you for replay but this is just from a preset point A to a preset point B. What i m looking for is to locate user using geolocation and to give him directions to a preset location.
So instead of Tokyo Station i will have my device location.


#4

I do have an advice from someone but i just can t put this together.

Before starting direction service, get the location of the user like this:

       $scope.centerOnMe = function() {
       if (!$scope.map) {
       return;
   }
  $scope.loading = $ionicLoading.show({
    content: 'Getting current location...',
  });
  navigator.geolocation.getCurrentPosition(function(position) {
    var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    $scope.positions.push({
      lat: pos.k,
      lng: pos.B
    });
    console.log(pos);
    $scope.map.setCenter(pos);
    $ionicLoading.hide();
  });
};

Then access the location you just got in your direction request like:

// directions object -- with defaults
$scope.directions = 
  origin: pos.k + "," + pos.B,
  destination: "White City, London W12 7RQ",
  showList: false
}

#5

Try this hope it finds you well.