2012-04-03 148 views

回答

9

从我的个人代码库。 ;)

public static Intent viewOnMap(String address) { 
    return new Intent(Intent.ACTION_VIEW, 
         Uri.parse(String.format("geo:0,0?q=%s", 
               URLEncoder.encode(address)))); 
} 

public static Intent viewOnMap(String lat, String lng) { 
    return new Intent(Intent.ACTION_VIEW, 
         Uri.parse(String.format("geo:%s,%s", lat, lng))); 
} 
0

您可以使用Google Geocoding API将您的物理地址转换为经度和纬度。 API将其返回到XML或JSON格式。你只需要解析数据来获取经纬度。接收到经纬度后,您可以在mapview上加载它。

地理编码API链接:

https://developers.google.com/maps/documentation/geocoding/

希望这有助于。

25

使用下面的代码,

String map = "http://maps.google.co.in/maps?q=" + str_location; 

//其中str_location是地址字符串

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(map)); 
     startActivity(i); 
1

更改此URL的大胆部分公司地址。 http://maps.google.com/maps/geo?q=620 + 8 +大道+新+纽约,+ NY + 10018,+美国 &输出= CSV & OE:如果你有一个加号(+)字符替换所有的空格,但应与空间工作太这是最好的= utf8 & sensor = false

向上面的URL提出请求。欲了解更多信息,请参阅http://androidadvice.blogspot.in/2010/09/asynchronous-web-request.html

这将生成一个看起来像这样的代码:

200,8,40.7562008,-73.9903784 

第一个数字200表示,该地址是好的。第二个数字8表示地址的准确度。最后两个数字,40.7562008和-73.9903784,是这个地址的经度和纬度。使用这些让你的谷歌地图工作。

注:以上步骤已经从http://webdesign.about.com/od/javascript/ss/add-google-maps-to-a-web-page_2.htm

0

复制2017年的建议是使用Google Maps URLs API,它提供通用的跨平台的网址,由谷歌的做法。您可以在您的意图中使用这些网址。从文件,例如URL的

例子:

https://www.google.com/maps/search/?api=1&query=centurylink+field

希望这有助于!

相关问题