At the moment i have a map that can give directions from preset point A to preset point B, but i would like to have directions from user location to a preset point like in this example:
http://jquery-ui-map.googlecode.com/svn/trunk/demos/jquery-google-maps-mobile.html#directions_map
My controller code is:
.controller('ContactCtrl', function($scope, $document, $ionicLoading) {
// map object
$scope.map = {
control: {},
center: {
latitude: 51.51139,
longitude: -0.2237284
},
zoom: 14
};
// marker object
$scope.marker = {
center: {
latitude: 51.51139,
longitude: -0.2237284
}
}
// instantiate google map objects for directions
var directionsDisplay = new google.maps.DirectionsRenderer();
var directionsService = new google.maps.DirectionsService();
var geocoder = new google.maps.Geocoder();
// directions object -- with defaults
$scope.directions = {
origin: "this shoud be user ",
destination: "White City, London W12 7RQ",
showList: false
}
// get directions using google maps api
$scope.getDirections = function () {
var request = {
origin: $scope.directions.origin,
destination: $scope.directions.destination,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
directionsDisplay.setMap($scope.map.control.getGMap());
directionsDisplay.setPanel(document.getElementById('directionsList'));
$scope.directions.showList = true;
} else {
alert('Google route unsuccesfull!');
}
});
}
})
Any ideas?