Android Google Maps API v2 start navigation

白昼怎懂夜的黑 提交于 2020-01-02 15:02:47

问题


I have an app that displays a map with a marker. When the user touches the marker I want to start navigation for them.

Is there an Intent/Activity that I can pass a longitude and latitude and start theusers navigation app?

Thanks for any help.


回答1:


I solved it like this. The url posted is similar.

Intent navigation = new Intent(
            Intent.ACTION_VIEW,
            Uri.parse("http://maps.google.com/maps?saddr=START_LAT,START_LON&daddr=END_LAT,END_LON"));
startActivity(navigation);

Where Start is the START_LON and START_LAT is the longitude and latitude and END_LON, END_LAT is the end




回答2:


That works fine:

    googleMap.setMyLocationEnabled(true);

    LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Criteria cri = new Criteria();
    bestProvider = locManager.getBestProvider(cri, true);

    Location loc = locManager.getLastKnownLocation(bestProvider);
    String latMy = String.valueOf(loc.getLatitude());
    String lngMy = String.valueOf(loc.getLongitude());

    Toast.makeText(this, "Navigation", Toast.LENGTH_SHORT).show();
    String url = "http://maps.google.com/maps?saddr=" + latMy + ","
            + lngMy + "&daddr=" + "18.7703500,19.4534500";

    Intent navigation = new Intent(Intent.ACTION_VIEW);
    navigation.setData(Uri.parse(url));

    startActivity(navigation);



回答3:


Use :

Uri gmmIntentUri = Uri.parse("google.navigation:q="+"18.7703500,19.4534500");
                Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
                mapIntent.setPackage("com.google.android.apps.maps");
                startActivity(mapIntent);


来源:https://stackoverflow.com/questions/15027867/android-google-maps-api-v2-start-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!