Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
554 views
in Technique[技术] by (71.8m points)

android - How to Launch Google Map Intent with My Current Location

Im a newbie here in android programming. Here is my simple code just to launch the intent with the given coordinates. The problem is, how to get my current location and use it to show my current location whenever the google map intent starts.

public void viewroute (View view)
{
    if  (view.getId()==R.id.ViewRoute)
      {
        Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("geo:9.8500,124.1435"));
        startActivity(intent);
      }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you have to try like this

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);

for more information visit here : https://developer.android.com/guide/components/intents-common.html#Maps

if you need with direction follow this

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
    Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);

Hope it will help you :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...