对您的位置进行地理编码发现 android eclipse
我的代码当前在地图上显示用户位置...使用下面的代码
private void initMyLocation() {
final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
overlay.enableMyLocation();
overlay.runOnFirstFix(new Runnable() {
public void run() {
controller.setZoom(8);
controller.animateTo(overlay.getMyLocation());
}
});
map.getOverlays().add(overlay);
}
我想使用用户的当前位置并对其执行地理编码以将地址显示为吐司消息..我是否必须删除上面的代码并通过单独的经度和纬度值检索位置?最好我不想去更改上面的代码,因为它已经可以工作了。我似乎找不到任何好的教程。有人可以指导我一个吗? 谢谢
My code currently displays the users location on a map... using the code below
private void initMyLocation() {
final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
overlay.enableMyLocation();
overlay.runOnFirstFix(new Runnable() {
public void run() {
controller.setZoom(8);
controller.animateTo(overlay.getMyLocation());
}
});
map.getOverlays().add(overlay);
}
I want to use the current location of the user and perform geocding on it to display the address as a toast message.. Would i have to delete the code above and retrieve the location by separate longitude and latitude values? Preferably i wouldnt want to go changing the code above as it already works.. I can't seem to find any good tutorials out there.. Could someone please direct me to one?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
MyLocationOverlay
已经实现了LocationListener
,因此您可以简单地对其进行子类化并重写onLocationChanged
侦听器方法,并在那里执行地理编码(最好在新线程/异步任务以避免阻塞覆盖处理!)。类似于:
另一个选项可能是编写一个自定义
LocationListener
并注册位置更新,并执行与上面代码中几乎相同的操作。 IMO,这可能是多余的并且不必要地昂贵,因为如上所述,您已经有一个LocationListener
实现可以挂钩,那么为什么还要编写另一个实现呢?Since
MyLocationOverlay
already implementsLocationListener
, you could simply subclass it and override theonLocationChanged
listener method and perform your geocoding there (preferably in a new thread/async task to avoid blocking the overlay processing!).Something like:
The other option might be to write a custom
LocationListener
and register for updates for location and do pretty much the same thing as in the code above. IMO, this is probably redundant and unnecessarily expensive since, as explained above, you already have aLocationListener
implementation to hook into so why write another?