簡體   English   中英

地圖意圖未顯示指定位置

[英]Maps Intents don't show specified location


我的申請有問題。 我想使用代碼位置中定義的位置打開Goog​​le Maps,因此我將數據設置為意圖,但是地圖始終在我的位置上打開(不是代碼1中指定的位置)。

這是代碼:

String addressString = "1600 Amphitheatre Parkway, CA";

Uri locationUri = new Uri.Builder();
        .scheme("geo")
        .path("0,0")
        .query(addressString);
        .build();

Intent mapIntent = new Intent(Intent.ACTION_VIEW, locationUri);
mapIntent.setPackage("com.google.android.apps.maps");

if(intent.resolveActivity(getPackageManager()) != null)
    startActivity(mapIntent);


有誰知道如何處理這種情況? 我在手機和虛擬設備上嘗試過,但兩者均無法正常工作。

以這種方式使用它可以經緯度打開:

double lat = YOUR_LATITUDE;
double lng = YOUR_LONGITUDE;
String placeLabel = YOUR_PLACE_LABEL;
String uri = String.format(Locale.ENGLISH, "geo:%f,%f?q=%f,%f(%s)", lat, lng, lat, lng, placeLabel);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);

如果要使用地址打開地圖,請將de uri替換為:

geo:0,0?q=my+street+address

query(addressString)更改為appendQueryParameter("q", addressString) ,您將獲得所需的內容:

Uri locationUri = new Uri.Builder()
        .scheme("geo")
        .path("0,0")
        .appendQueryParameter("q", addressString)
        .build();

暫無
暫無

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

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