簡體   English   中英

使用特定坐標從我的Android應用中打開Goog​​le地圖

[英]Open Google Maps from my Android App with Specific Coordinates

我的應用程序有一個地點列表,當按下時,它將打開其特定頁面,顯示更多地點信息。

頁面內部是一個ImageView(地圖標記),如果按下該按鈕,它將打開一個具有特定地點坐標的Google Map App。

它是這樣的:地點清單->地點的特定頁面->帶有坐標的GOOGLE MAP APP(請檢查所附的圖片。)

在此處查看圖像。

此代碼僅在打開1個地方時可以正常工作。

public void MapClick (View v) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:13.669595,124.4130464?q=13.669595,124.4130464(Binurong Point)"));
        startActivity(intent);
    }

如何將坐標從數組傳遞到ImageView(地圖標記),以便如果按下它,它將基於它在何處打開Goog​​le Map App?

這是我的出發點:

    String[] attractgeocoordinates = {
//          Place #1
            "13.5735488,124.1371557",

//         Place #2
            "13.7077914,124.3876623",
}

謝謝!

嘗試這個:

String[] attractgeocoordinates = {"13.5735488,124.1371557", "13.7077914,124.3876623"};
String[] mainLatLng =attractgeocoordinates[0].split(",");

String lattitude=mainLatLng[0];
String longitude=mainLatLng[1];

String geoUri = "http://maps.google.com/maps?q=loc:" + lattitude + "," + longitude + " (" + Binurong Point + ")";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(geoUri ));
context.startActivity(intent);

可能重復的答案在這里

雖然,作為一個額外的例子:

String urlAddress = "http://maps.google.com/maps?q="+ mLatitude  +"," + mLongitude +"("+ mMarkerName + ")&iwloc=A&hl=es";
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress));
                intent.setPackage("com.google.android.apps.maps");
                if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
                    startActivity(intent);
                }

您必須從列表視圖中獲取選定的位置,並訪問該特定值,然后將內容通過意圖傳遞到圖像視圖。

Example : 
listView.setOnItemClickListener(new OnItemClickListener()
 {

 @Override
 public void onItemClick(AdapterView<?> parent, View view,
 int position, long id) 
{ 
Intent intent=new Intent(ListviewActivity.this,ImageviewActivity.class)
intent.putString("value1",attractgeocoordinates[0]);
intent.putString("value1",attractgeocoordinates[1]);
startactivity(intent);

}

 }
 });

}

在此處更改您的緯度坐標。 它將啟動google maps應用程序,並為地圖中的坐標繪制圖釘。

String latlng=13.326574+","+75.770282+("CSM");
    Uri mapUri = Uri.parse("geo:0,0?q="+latlng);
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, mapUri);
    mapIntent.setPackage("com.google.android.apps.maps");
    startActivity(mapIntent);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM