2

I have a problem to let Google Maps playing automatically after opened...

Example: I have put intent code and yes it will open Google maps according to my latitude and longitude... But, I still need to press a button to start Google Maps to direct me. How can I make Google Map open automatically after opened by intent without pressed by users? Is it possible ?

Here is my code,

private void turnOnMap()
{
    String labelMap = "Target";
    String geouri = "geo:0,0?q=-6.908572,107.610923(XXI)";
    Intent mapInt = new Intent(Intent.ACTION_VIEW, Uri.parse(geouri));
    startActivity(mapInt);
}

I got some information of intent code from these open google maps through intent for specific location in android and Android - How to launch Google map intent in android app with certain location, zoom level and marker and also latest uri from official android site https://developer.android.com/guide/components/intents-common.html#Maps

And, they don't explain what command should I add to play Google Maps automatically after opened...

Hope you can help me guys... Thank you very much for your time and information

pgSystemTester
  • 8,979
  • 2
  • 23
  • 49
Nicky Puff
  • 149
  • 3
  • 14
  • What about the [official documentation](https://developers.google.com/maps/documentation/urls/android-intents#launch_turn-by-turn_navigation)? – Eselfar Jul 26 '17 at 18:05
  • Maybe you should read about [Google Maps URLs](https://developers.google.com/maps/documentation/urls/guide#directions-action). – xomena Jul 26 '17 at 19:24
  • I got it mate... here we go https://developers.google.com/maps/documentation/urls/android-intents#launch_turn-by-turn_navigation Thank you @Eselfar for your suggestion.. works ;) and xomena for more details information Google Map API – Nicky Puff Jul 27 '17 at 01:46

1 Answers1

11
String strUri = "http://maps.google.com/maps?q=loc:" + latitude + "," + longitude + " (" + yourLocationName + ")";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(strUri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
phatnhse
  • 3,870
  • 2
  • 20
  • 29