Page 1 of 5

Setting permanent Google Maps destination while geolocation sets start point.

Posted: Wed Jun 05, 2013 8:39 pm
by Troy Cooper

I am trying to build Google Directions into my app but I want to set the destination permanently and have the start point be set by the phones geolocation automatically. I tried modifying the code given in the tutorial under "Build a mobile app with Google Map and Google Directions API" and "Building a mobile app with Google Map and Geolocation" but it didn't work.


Setting permanent Google Maps destination while geolocation sets start point.

Posted: Wed Jun 05, 2013 8:48 pm
by Kateryna Grynko

Hi Troy,

What exactly doesn't work?
Are there any errors in console?
Did you try to do the tutorial exactly?


Setting permanent Google Maps destination while geolocation sets start point.

Posted: Wed Jun 05, 2013 8:55 pm
by Troy Cooper

Thanks for responding so quickly.:

You asked, "What exactly doesn't work?" and "Did you try to do the tutorial exactly?"
~ By following the tutorial, "Building a mobile app with Google Map and Geolocation" I was able to use the app to find my location. However, it would get rid of the marker that was on my business. I thought that if I could get it to give directions from where ever users are then the disappeared marker wouldn't really matter.
So, I tried the other tutorial "Build a mobile app with Google Map and Google Directions API" but tried to modify the code as I went along to make the geolocation was the start point in route guidance and my business as the destination. When I tested the app, the map appeared on screen without a problem but neither the geolocation or the route guidance worked at that point.

"Are there any errors in console?"
~ I don't know quite what this means. I did not get any error messages though.


Setting permanent Google Maps destination while geolocation sets start point.

Posted: Wed Jun 05, 2013 9:06 pm
by Kateryna Grynko

In Chrome / Mozilla Firefox click F12 to open Chrome developer console / Firebug.


Setting permanent Google Maps destination while geolocation sets start point.

Posted: Wed Jun 05, 2013 9:14 pm
by Troy Cooper

Okay


Setting permanent Google Maps destination while geolocation sets start point.

Posted: Wed Jun 05, 2013 9:23 pm
by Troy Cooper

I opened the web console in Firefox and retested the app. It says "Geolocation is not defined."


Setting permanent Google Maps destination while geolocation sets start point.

Posted: Wed Jun 05, 2013 9:31 pm
by Troy Cooper

Closer inspection shows that it says I have an error in my javascript on line 10. This is what I have as my javascript. How should I define "geolocation"?

var directionDisplay;
var directionsService = new google.maps.DirectionsService();

function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
}

function displayDirections(sourceAddress, destinationAddress, map) {
var request = {
origin: Geolocation,
destination: google.maps.LatLng(41.719111, -111.846469),
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
directionsDisplay.setMap(map);
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
alert("Directions query unsuccessful. Response status: " + status);
}
});
}


Setting permanent Google Maps destination while geolocation sets start point.

Posted: Wed Jun 05, 2013 10:43 pm
by Igor

Hello.

You should define "Geolocation" variable.
code
var Geolocation=put here some value;
/code


Setting permanent Google Maps destination while geolocation sets start point.

Posted: Thu Jun 06, 2013 12:29 am
by Troy Cooper

Hey Igor,

How do I define "Geolocation" so that the mobile device the app is installed on inserts the proper value? I know pretty much nothing about programming... Sorry!


Setting permanent Google Maps destination while geolocation sets start point.

Posted: Thu Jun 06, 2013 6:14 am
by Maryna Brodina

Hello! Could you give us your public app link?