地理编码器不断返回 true
我的应用程序使用 GeoCoder
不断将字符串返回为 true。这是我的代码。
public boolean address(){
Geocoder geoCoder =
new Geocoder
(getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(LocationManagerHelper.getLatitude()/1E6, LocationManagerHelper.getLongitude()/1E6, 1);
String addes = "";
if (addresses.size() > 0)
{
for (int i=0; i<addresses.get(0).getMaxAddressLineIndex();
i++)
addes += addresses.get(0).getAddressLine(i) + "\n";
}
}
catch (IOException e) {
e.printStackTrace();
}
return true;
}
我将其称为文本视图。
add.append(""+ address()
+ '\n');
它有点工作,只是它不显示地址,而是显示 true
任何人都可以告诉我这是为什么吗?
谢谢。
My application using a GeoCoder
keeps returning the string to true. here is the code I have.
public boolean address(){
Geocoder geoCoder =
new Geocoder
(getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(LocationManagerHelper.getLatitude()/1E6, LocationManagerHelper.getLongitude()/1E6, 1);
String addes = "";
if (addresses.size() > 0)
{
for (int i=0; i<addresses.get(0).getMaxAddressLineIndex();
i++)
addes += addresses.get(0).getAddressLine(i) + "\n";
}
}
catch (IOException e) {
e.printStackTrace();
}
return true;
}
and I call that into a text view.
add.append(""+ address()
+ '\n');
it works somewhat except for it doesn't show the address and instead shows true
can any one tell me why this is?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用 return 关键字返回地址字符串,并将方法返回类型更改为 String:
You need to return the address string by using the return keyword, and changing your method return type to a String:
您需要在
try
块外部初始化结果String
变量,然后将方法的返回类型更改为String
并在使用地址中的行对其进行扩充后,确实会返回结果String
变量。但是,实际上,这是基本的 Java 编程,因此在深入研究 Android 等框架之前,我衷心建议您先学习该语言。
You need to initialize the result
String
variable outside thetry
block, then change the method's return type toString
and indeed return the resultString
variable after having augmented it with the lines from the address.But, really, this is basic Java programming, so before delving into a framework such as Android I would heartily suggest you learn the language first.