Page 1 of 1

Mobile app with Google Map and automatic Google Directions API

Posted: Mon Jul 21, 2014 9:47 pm
by silvère Akouala

Hi,

I followed this tutorial to add directions to my app:

http://devcenter.appery.io/tutorials/...

I call the initialize method once the page is loaded and the displayDirections method on page show. It's working on test link not on mobile.

How can I do because I wanted to call displayDirections method automatically.

Best regards.


Mobile app with Google Map and automatic Google Directions API

Posted: Tue Jul 22, 2014 3:54 am
by Yurii Orishchuk

Hi Silvère,

Please add some alert to the page load event to be ensure your code runs.

Also please show us some screen shots to clarify your question.

Regards.


Mobile app with Google Map and automatic Google Directions API

Posted: Wed Jul 23, 2014 7:36 am
by silvère Akouala

Dear Yurii,

Please find fonctions and the screen shot.
Best regards.

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

function displayDirections(sourceAddress, destinationAddress, map) {
var request = {
origin: sourceAddress,
destination: destinationAddress,
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);
}
});
}
Image


Mobile app with Google Map and automatic Google Directions API

Posted: Thu Jul 24, 2014 12:22 am
by Yurii Orishchuk

Hi Silvere,

Please use following solution:

  1. Remove all "page load" and "page show" event handlers.

  2. Add "page load" JS event handler with following code:

    pre

    initialize();

    var sourceAddress = Appery("inputSource").val();
    var destinationAddress = Appery("inputDestination").val();

    //Note you need replace "directionsMap" with your map component name.
    var map = Appery("directionsMap").options.mapElement.gmap('get', 'map');

    displayDirections(sourceAddress, destinationAddress, map);

    /pre

    //Note you need replace "directionsMap" with your map component name.

    Also, when you write some JS code please wrap it with pre tag:

    pre
    <pre
    here is your code
    </pre
    /pre

    Regards.