验证 Android 中的地址输入

发布于 2024-12-24 15:49:32 字数 129 浏览 6 评论 0原文

在我的应用程序中,我必须输入用户地址(美国)。用户需要输入有效的地址。我怎样才能实现这个目标?有没有图书馆可以帮助我了解州名、城市名和街道名?如果可能的话我想使用自动打字。我读过地理编码,但我认为它对我没有帮助,因为用户没有从当前位置输入地址。

In my app, I have to take in a user address (US). The user needs to type in a valid address. How can I achieve this? Is there any library which can help me with the names of states, cities and street names? I would like to use autotype if possible. I read GeoCoding but I don't think it will help me as the user is not entering the address from the current location.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北笙凉宸 2024-12-31 15:49:32

这就是我使用 Google API 查找位置的方法。也许它会对你有所帮助:

     Geocoder geoCoder = new Geocoder(context, Locale.getDefault());    
        try {
            List<Address> addresses = 
                    geoCoder.getFromLocationName(travel.getAddress() + "," + 
            travel.getCity() + "," + travel.getState() + "," + travel.getCountry(), 3);

            if (addresses.size() > 0) {
                point = new GeoPoint(
                        (int) (addresses.get(0).getLatitude() * 1E6), 
                        (int) (addresses.get(0).getLongitude() * 1E6));
                travel.setLatitude(String.valueOf(point.getLatitudeE6()));
                travel.setLatitude(String.valueOf(point.getLongitudeE6()));
                long res = travel.update(context, null);
                if (res < 1){
                    result = false;
                }

            }    
        } catch (IOException e) {
            e.printStackTrace();
            result = false;
        }

This is what I do to find a location using Google API. Maybe it will help you:

     Geocoder geoCoder = new Geocoder(context, Locale.getDefault());    
        try {
            List<Address> addresses = 
                    geoCoder.getFromLocationName(travel.getAddress() + "," + 
            travel.getCity() + "," + travel.getState() + "," + travel.getCountry(), 3);

            if (addresses.size() > 0) {
                point = new GeoPoint(
                        (int) (addresses.get(0).getLatitude() * 1E6), 
                        (int) (addresses.get(0).getLongitude() * 1E6));
                travel.setLatitude(String.valueOf(point.getLatitudeE6()));
                travel.setLatitude(String.valueOf(point.getLongitudeE6()));
                long res = travel.update(context, null);
                if (res < 1){
                    result = false;
                }

            }    
        } catch (IOException e) {
            e.printStackTrace();
            result = false;
        }
舞袖。长 2024-12-31 15:49:32

为什么不验证区号?这样做你应该可以得救。

Why not validate the area code? You should be save by doing that.

素食主义者 2024-12-31 15:49:32

有多种方法可以清理地址输入并将其标准化为预期格式。但验证地址以确保其真实且正确的唯一真正方法是使用地址验证服务。

标准化地址就是为了确保一切看起来都不错——就像格式化和标准化电话号码或电子邮件地址一样。但仅仅拥有看起来不错的数据还不够。您需要良好的数据。举个例子,如果用户提供了一张可能的信用卡,您会接受订单吗?或者您想要一张好的信用卡?地址也是如此。如果您正在收集一个地址,那么如果您知道该地址是真实的、可交付的并且可以用于您的预期目的,那肯定会很高兴。否则,它只是垃圾数据——垃圾输入,垃圾输出。

幸运的是,在您的情况下,由于用户使用的是基于 Android 的设备,因此他们很可能具有互联网连接,这允许您对第 3 方地址验证服务执行查询。有许多服务可以提供街道地址验证。我是 SmartyStreets 的创始人。我们的 LiveAddress API 可能正是您所寻找的。而且,根据您的数量和业务,它也可能是完全免费的。如果没有,也没什么大不了的,您还可以使用其他服务。

There are various ways to clean up address input and to standardize it into the expected format. But the only real way to validate an address to ensure that it's both real and correct is to use an address verification service.

Standardizing an address is all about ensuring things look good--like formatting and standardizing a telephone number or email address. But having data that only looks good isn't enough. You need data that is good. As an example, would you accept an order if a user provides a credit card that might be good? Or do you want a credit card that is good? It's the same with addresses. If you're collecting an address, it would sure be nice to know that it's real, deliverable, and can be used for your intended purpose. Otherwise, it's just junk data--garbage in, garbage out.

Fortunately in your case, because the user is on an Android-based device, they will most likely have internet connectivity which allows you to perform a query to a 3rd-party address verification service. There are a number of services out there that provide street address verification. I'm the founder of one called SmartyStreets. Our LiveAddress API might just be what you're looking for. And, depending upon your volume and business, it may very well be completely free as well. If not, no big deal, there are other services out there that you can utilize.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文