Warm tip: This article is reproduced from serverfault.com, please click

android-如何在带有标记的Google map中定位到特定位置?

(android - how to Intent to particular location in google maps with marker on it?)

发布于 2020-11-28 10:57:31

我正在使用Firebase作为后端创建一个游览应用程序。我需要知道如何在标记上指定特定的位置吗?

Intent i = new Intent (Intent.ACION_VIEW) 像这样,还是有其他与标​​记有关的方法吗?

Questioner
MadhanMohan
Viewed
11
Mohammed Alaa 2020-11-28 19:24:28

尝试使用此示例来启动具有特定纬度和经度的Google map

public void gotToLocation(String markerName,Float latitude, Float longitude ) {
    String uri = String.format(Locale.ENGLISH, "geo:0,0?q=%f,%f(%s)", latitude,longitude,markerName);
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));;
    mapIntent.setPackage("com.google.android.apps.maps");
    if (mapIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        startActivity(mapIntent);
    }
}

然后这样称呼它

gotToLocation("MyLocation",34.99,-106.61);