【问题标题】:How to grab an coordinates of an address a user has entered into google maps?如何获取用户输入谷歌地图的地址坐标?
【发布时间】:2015-09-16 01:48:04
【问题描述】:
所以在我的应用程序中,用户输入“伦敦麦当劳”之类的地方(或地址),然后在谷歌地图找到特定位置后,我想获取这些坐标并在我的应用程序中使用它们。有谁知道我该怎么做?!?!
如何访问谷歌应用程序的坐标,或者如果我使用片段活动,我如何输入搜索框让他们输入地址并获取这些坐标?我不确定哪种方式更容易。
请帮忙!
【问题讨论】:
标签:
android
google-maps
android-activity
android-fragmentactivity
【解决方案1】:
试试这个代码:
List<Address> foundAddresses = null;
foundAddresses = new Geocoder(this).getFromLocationName("McDonalds in London", 1);
double latitude = foundAddresses.get(0).getLatitude();
double longitude = foundAddresses.get(0).getLongitude();
如果您希望"McDonalds in London" 有多个匹配项,您可以在调用getFromLocationName() 时传递任意号码。