实施地理编码器
我试图在实现 Runnable
的类中实现 Geocoder
,但在这一行出现错误:
Geocoder myLocation = new Geocoder(this, Locale.getDefault());
我不认为 Android 喜欢 this
。
但是我应该传递什么上下文才能使其发挥作用?
public class ClientThread_special implements Runnable {
public void run() {
Geocoder myLocation = new Geocoder(this, Locale.getDefault());
}
}
我正在尝试在不扩展 Activity
的类中实现 Geocoder
,但在传递 Geocoder
构造函数的上下文时遇到问题。
Android 不喜欢在我的类中使用 this
。我也尝试过 getApplicationContext
...但它仍然说“无法解决...”。
I'm trying to implement Geocoder
in a class that implements Runnable
and I get error at this line:
Geocoder myLocation = new Geocoder(this, Locale.getDefault());
I don't think Android likes this
.
But what context should I pass in for this to work?
public class ClientThread_special implements Runnable {
public void run() {
Geocoder myLocation = new Geocoder(this, Locale.getDefault());
}
}
I'm trying to implement the Geocoder
in a class that doesn't extend Activity
and I have problems in passing the context for the Geocoder
constructor.
Android doesn't like this
for my class. I also tried with getApplicationContext
...but still it says that "it can't be resolved..".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须以某种方式传递 Context 实例。没有它,地理编码器将无法工作。
You must pass Context instance somehow. Without it Geocoder won't work.
如果您需要 Context 实例并且不需要活动,请使用 Service 扩展类 ClientThread_special ,我认为您将不需要 Runnable 。
If you need Context instance and don't need an activity,extend the class ClientThread_special with Service and I think you wont need Runnable then.