通过针对android中特定位置的意图打开谷歌地图 [英] open google maps through intent for specific location in android
问题描述
我正在设计一个应用程序,我想在其中显示地图上的特定位置.我正在传递已放置在 Google Map
上的地址的 String
.以下是我的 Intent
代码..
I'm designing one application in which I want to show specific location on Map.
I'm passing String
of address which is already placed on Google Map
.
Following is my Intent
code..
String url = "http://maps.google.com/maps?daddr="+address;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
但它给了我谷歌地图以获得方向.我知道为什么会这样,因为我在 url
中使用了 daddr
但我不知道在特定位置使用什么..请告诉我在那里使用什么..
But it gives me Google Map for getting direction. I know why that so, because I used daddr
in url
but I don't know what to use for specific location..Please tell me what to use there..
推荐答案
我还没有测试过,但你可以试试:
I have not tested this but you could try :
第一种方法:
String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
context.startActivity(intent);
这可能不适用于 Google 地图 7,0
This might not work with Google maps 7,0
因此您可以将 uri 更改为:
hence you could change the uri to :
第二个选项:
String geoUri = "http://maps.google.com/maps?q=loc:" + lat + "," + lng + " (" + mTitle + ")";
其中 mTitle
是位置的名称.
where mTitle
is the name of the location.
第三种选择:
geo:0,0?q=my+street+address
第四个选项:
String map = "http://maps.google.co.in/maps?q=" + yourAddress;
希望有效并有所帮助 :D ..
Hope that works and helps :D..
这篇关于通过针对android中特定位置的意图打开谷歌地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!