简体   繁体   English

Android应用程式,Google Maps Java的api位置验证

[英]Android app, Google maps api location validation for java

I'm using Android Studio to create an app that utilizes google maps api. 我正在使用Android Studio创建一个利用Google Maps API的应用程序。 I am having trouble validating if the user input is an actual location. 我在验证用户输入是否为实际位置时遇到麻烦。

ie if the user enters "fdfdfaef", program crashes. 即,如果用户输入“ fdfdfaef”,则程序崩溃。

i have the following code to store the user "location" input: 我有以下代码来存储用户“位置”输入:

address = geocoder.getFromLocationName(location, 1)

Any help on how to check if the input is valid or not or at least to prevent a crash. 关于如何检查输入是否有效或至少防止崩溃的任何帮助。 Thanks and appreciate it. 谢谢,并感谢它。

Since you haven't posted any code, I will go out on a limb and suggest that you might be doing this on your main UI thread. 由于您尚未发布任何代码,因此我会不知所措,建议您可能在主UI线程上执行此操作。

From the doc , 文档中

The query will block and returned values will be obtained by means of a network lookup. 该查询将被阻止,并且将通过网络查找获得返回的值。 The results are a best guess and are not guaranteed to be meaningful or correct. 结果是最佳猜测,不能保证是有意义或正确的。 It may be useful to call this method from a thread separate from your primary UI thread. 从与主UI线程分开的线程中调用此方法可能很有用。

Try doing a async task that requests information using the Geocoding API. 尝试执行使用Geocoding API请求信息的异步​​任务。 On getting a result, update the UI. 获得结果后,更新UI。 Offloading to an AsyncTask will prevent the crash, at the very least. 卸载到AsyncTask至少可以防止崩溃。

Does that help you? 这对您有帮助吗?

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

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