简体   繁体   English

如何使用纬度和经度获取地址信息?

[英]How can I get address information using latitude and longitude?

I made this tutorial for get user's address and location but I got error when I changed AVD's location.我制作了教程来获取用户的地址和位置,但是当我更改 AVD 的位置时出现错误。 When I didn't call getCityName function at getLastLocation function, I can get user's location but when I call it, it gave that error.当我没有在getLastLocation函数中调用getCityName函数时,我可以获得用户的位置,但是当我调用它时,它给出了那个错误。 How can I solve it?我该如何解决?

it was give an error which was :它给出了一个错误:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.slidework3, PID: 15792
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
     Caused by: java.io.IOException: grpc failed
        at android.location.Geocoder.getFromLocation(Geocoder.java:136)
        at com.example.slidework3.AdresPage.getCityName(AdresPage.kt:152)
        at com.example.slidework3.AdresPage.access$getCityName(AdresPage.kt:20)
        at com.example.slidework3.AdresPage$getLastLocation$1.onComplete(AdresPage.kt:66)
        at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

Edit: I tried real device, location services working well I can get city name, street name etc. But in simulator it was give error again.编辑:我尝试了真实设备,位置服务运行良好,我可以获得城市名称、街道名称等。但在模拟器中再次出错。 I tried to change AVD's location after that it was going to crash.之后我试图更改 AVD 的位置,因为它会崩溃。 I believe solution is simple but I don't know how can I search this situation.我相信解决方案很简单,但我不知道如何搜索这种情况。

Try run the operation in a new Thread, and then if I need to update some UI view I'll do it on runOnUiThread.尝试在新线程中运行该操作,然后如果我需要更新某些 UI 视图,我将在 runOnUiThread 上进行。

https://developer.android.com/training/location/display-address#java https://developer.android.com/training/location/display-address#java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM