我有一个 Java 应用程序,我想找出访问者的位置.API 会给我一个访客的邮政编码,然后基于该邮政编码,我会找到一个查询并在我的应用程序中获取 25/50 英里半径内的用户.或者,访问者可以输入他们感兴趣的邮政编码,应用程序应该返回半径为 x 英里的用户.对于在系统中注册的用户,我们只有他们的邮政编码.我查看了一些选项,但没有找到确切的解决方案.我不想下载邮政编码数据库并维护它们.我不认为 Google API 支持这种东西.
I have a Java application and I would like to find out the location of a visitor. The API would give me a the zip code of visitor and then based on that zip code, I will find fire a query and get users in my application within 25/50 mile radius. Alternatively visitor can type in the zip code of their interest and application should return users withing x mile of radius. For the users who are registered in the system, we have only their zip code. I have looked around some options but not found the exact solution. I do not want to download the database of zip code and maintain them. I do not think Google API support this kind of stuff.
我找不到任何提供 API 的服务.经过大量研究,我发现您必须将邮政编码及其纬度和经度位置下载到表格中.然后计算要搜索的半径内的坐标.这是对我帮助很大的网站.http://www.dougv.com/2009/03/27/getting-all-zip-codes-in-a-given-radius-from-a-known-point-zip-code-via-php-and-mysql/
I could not find any service which offers API . After much research i found that you will have to download zip codes along with their latitude and longitude positions into a table. Then calculate co ordinates within the radius you want to search. This is the website which helped me a lot. http://www.dougv.com/2009/03/27/getting-all-zip-codes-in-a-given-radius-from-a-known-point-zip-code-via-php-and-mysql/
如果你真的不想使用 php,这里是 java 中的计算
Here is the calculation in java if you really if you do not want to work with php
//这您将通过根据邮政编码查询数据库来获得双纬度 = Double.parseDouble(zipCode.getLatitude());双经度 = Double.parseDouble(zipCode.getLongitude());
//this you will get by querying the database against the zip code Double latitude = Double.parseDouble(zipCode.getLatitude()); Double longitude = Double.parseDouble(zipCode.getLongitude());
Double latN =Math.asin(
Math.sin(Math.toRadians(latitude)) * Math.cos(distance/radius) +
Math.cos(Math.toRadians(latitude)) * Math.sin(distance/radius) * Math.cos(Math.toRadians(0)));
Double latS =Math.asin(
Math.sin(Math.toRadians(latitude)) * Math.cos(distance/radius) +
Math.cos(Math.toRadians(latitude)) * Math.sin(distance/radius) * Math.cos(Math.toRadians(180)));
Double longE = Math.toRadians(longitude) +
Math.atan2(
Math.sin(Math.toRadians(90)) * Math.sin(distance/radius)* Math.cos(Math.toRadians(latitude))
, Math.cos(Math.toRadians(distance/radius)) - Math.sin(Math.toRadians(latitude))* Math.sin(Math.toRadians(latN)) );
Double longW = Math.toRadians(longitude) +
Math.atan2(
Math.sin(Math.toRadians(270)) * Math.sin(distance/radius)* Math.cos(Math.toRadians(latitude))
, Math.cos(Math.toRadians(distance/radius)) - Math.sin(Math.toRadians(latitude))* Math.sin(Math.toRadians(latN)) );
System.out.println("Latutude N "+Math.toDegrees(latN) +" Latitide S "+Math.toDegrees(latS) +">>> Longitude E "+Math.toDegrees(longE) +" Longitude W "+Math.toDegrees(longW));
这篇关于地理位置 API 和在半径内查找用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!