user2880026
user2880026

Reputation: 21

PhoneGap direction using native Google Maps

I have an app containing a button which should present the user with directions to a local business. I wish to supply the directions using Google Maps with the inclusion of step-by-step road directions from the user's current location.

I wish for the native Google Maps app to handle the directions, but when I tried a href of https://maps.google.com/maps?q=..., Google Maps in opening the user's web browser, rather than in their Google Maps app.

This web-based map is not providing the step-by-step directions that I desire - it only provides an overhead view from point A to point B.

I have also tried

<a href="geo:38.897096,-77.036545">businesname</a>

and

<a href="geo:someAddressHere">businessname</a>

These hrefs do launch the native Google Maps app, but step-by-step direction are not shown.

In summary: how can I display a Google Map view to give step-by-step directions (preferably using the native app).

Upvotes: 2

Views: 2513

Answers (3)

Aditya Raj
Aditya Raj

Reputation: 168

You don't need any plugin.
Just Use this for any version of phonegap but don't use href in phonegap 3x.
Use window.open();

For Navigation - window.open("google.navigation:q=23.3728831,85.3372199&mode=d" , '_system');

For Search - window.open("geo:0,0?q=pizza" , '_system');

Read Here - https://developers.google.com/maps/documentation/android/intents

Upvotes: 0

Emil Borconi
Emil Borconi

Reputation: 3467

If you DO NOT have inAppBrowser plugin loaded, you can do:

window.open("http://maps.google.com/maps?saddr=some+address&daddr=another+Address");

it will open a new browser window with the directions (but not the native app)

Or you can use the previous answer frouil, but to do so you must do the following. In your main Java file, add, before the super.loadUrl call:

appView.addJavascriptInterface(this, "YouActivityName");

Then from your javascript, you use following method:

window.YouActivityName.launchGMaps("http://maps.google.com/maps?saddr=some+address&daddr=another+Address");

If you omit the saddr part android will try to use your current location and start address

Upvotes: 1

Legisey
Legisey

Reputation: 513

What you are looking for is called an intent. It is a command that passes some informations to an other app an can launch it.

What I would do is adding a method in your code that is called when the user touches the button. This method would be something like:

//Pass the link to the itinerary you want
void launchGMaps(String link) {

    //Pass the link and the instruction to show something to an Intent
    Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(link));
    //Give the name of the app to start and the activity to start in this app.
    myIntent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
    //Gooooooooooo !
    startActivity(myIntent);
}

I hope it helped.

F

Upvotes: 1

Related Questions