[英]Maps Intents don't show specified location
I have a problem with my application. 我的申请有问题。 I want to open Google Maps with defined in code location, so I set the data to the intent, but maps open on my location all the time (not the specified in code one). 我想使用代码位置中定义的位置打开Google Maps,因此我将数据设置为意图,但是地图始终在我的位置上打开(不是代码1中指定的位置)。
Here is the code: 这是代码:
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);
Does anyone know how to handle this situation? 有谁知道如何处理这种情况? I tried on my phone and on the virtual device and it's not working on both. 我在手机和虚拟设备上尝试过,但两者均无法正常工作。
Use it this way to open with latitude and longitude: 以这种方式使用它可以经纬度打开:
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);
If you want to open the map with an address, replace de uri with: 如果要使用地址打开地图,请将de uri替换为:
geo:0,0?q=my+street+address
Change query(addressString)
to appendQueryParameter("q", addressString)
and you will rich what you want: 将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.