i want to get the latitude and longitude using the zipcode for android application
我想使用zipcode为Android应用程序获取经度和纬度
4 个解决方案
#1
21
This is a much simpler solution, assuming the geocoder services are present:
假设存在地理编码器服务,这是一个更简单的解决方案:
final Geocoder geocoder = new Geocoder(this);
final String zip = "90210";
try {
List<Address> addresses = geocoder.getFromLocationName(zipCode, 1);
if (addresses != null && !addresses.isEmpty()) {
Address address = addresses.get(0);
// Use the address as needed
String message = String.format("Latitude: %f, Longitude: %f",
address.getLatitude(), address.getLongitude());
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
} else {
// Display appropriate message when Geocoder services are not available
Toast.makeToast(this, "Unable to geocode zipcode", Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
// handle exception
}
#2
4
There is no rival of Google in GeoCoding :)
在GeoCoding中没有Google的竞争对手:)
You have to just make an http Get request for the following link. Here's a link
您只需要为以下链接发出http Get请求。这是一个链接
Just change the postal code Element According to your requirements. And Enjoy.
只需根据您的要求更改邮政编码元素即可。享受。
For further reference follow the link.Maps Geocoding Reference
有关进一步参考,请参阅link.Maps地理编码参考
#3
3
You could use YQL like so: select centroid from geo.places where text="ZIPCODE_HERE"
您可以像这样使用YQL:从geo.places中选择centroid,其中text =“ZIPCODE_HERE”
#4
2
You will have to use a Geocoding Service, like the ones provided by Google or the freely available Nominatim. Note that since you will be just providing a ZIP code, you might not get the results you want due to the inaccuracy of the address itself.
您将不得不使用地理编码服务,例如Google提供的服务或免费提供的Nominatim服务。请注意,由于您只是提供邮政编码,由于地址本身的不准确性,您可能无法获得所需的结果。
#1
21
This is a much simpler solution, assuming the geocoder services are present:
假设存在地理编码器服务,这是一个更简单的解决方案:
final Geocoder geocoder = new Geocoder(this);
final String zip = "90210";
try {
List<Address> addresses = geocoder.getFromLocationName(zipCode, 1);
if (addresses != null && !addresses.isEmpty()) {
Address address = addresses.get(0);
// Use the address as needed
String message = String.format("Latitude: %f, Longitude: %f",
address.getLatitude(), address.getLongitude());
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
} else {
// Display appropriate message when Geocoder services are not available
Toast.makeToast(this, "Unable to geocode zipcode", Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
// handle exception
}
#2
4
There is no rival of Google in GeoCoding :)
在GeoCoding中没有Google的竞争对手:)
You have to just make an http Get request for the following link. Here's a link
您只需要为以下链接发出http Get请求。这是一个链接
Just change the postal code Element According to your requirements. And Enjoy.
只需根据您的要求更改邮政编码元素即可。享受。
For further reference follow the link.Maps Geocoding Reference
有关进一步参考,请参阅link.Maps地理编码参考
#3
3
You could use YQL like so: select centroid from geo.places where text="ZIPCODE_HERE"
您可以像这样使用YQL:从geo.places中选择centroid,其中text =“ZIPCODE_HERE”
#4
2
You will have to use a Geocoding Service, like the ones provided by Google or the freely available Nominatim. Note that since you will be just providing a ZIP code, you might not get the results you want due to the inaccuracy of the address itself.
您将不得不使用地理编码服务,例如Google提供的服务或免费提供的Nominatim服务。请注意,由于您只是提供邮政编码,由于地址本身的不准确性,您可能无法获得所需的结果。