aleczandru
aleczandru

Reputation: 5469

Adding map functionality with phonegap

Hi I am developing a javascript heavy SPA application with Durandal framework which will be wrapped with phonegap.

I am very new to phonegap so it may be possible that when I was browsing the docs I could have missed the solution to my problem.

On my app I will have several places where the user will click on an address and the user should be taken to the default map app of the device.

For example: If I am using Android platform and google maps is my default app for maps I expect it to take me to that app , but if I am using iPhone I expect it to take me to the default map application that is set for iPhone.

Can this be done using phonegap? Thanks.

Upvotes: 1

Views: 162

Answers (1)

Sheetal
Sheetal

Reputation: 1366

Yes, this can be done:

if(navigator.userAgent.indexOf("Android") != -1) {
    // source addr is car addr and destination addr is current addr
    url = "http://maps.google.com/maps?saddr=" + position.coords.latitude + "," + position.coords.longitude + "&daddr="+sourceLat + "," +sourceLong ;

} else if (navigator.userAgent.indexOf("iPhone") != -1) {
    url = "maps:saddr=" +position.coords.latitude + "," + position.coords.longitude + "&daddr=" + sourceLat + "," + sourceLong;             
}

And open this URL in the webApp browser.

Upvotes: 1

Related Questions