Retrieving Longitude and Latitude fron address passed to server
I pose an i开发者_StackOverflow中文版nteresting question. What I'm trying to achieve is I have a list of merchants and their address. I want their longitude and latitude so I can determine if the user (using location listener) is within a one kilometre radius of that merchant. I have done the code to determine if they are within that radius.
What I need is the merchants longitude and latitude as I said. Is there a soap service that I can use to pass the address of the merchant and it responds with the longitude and latitude? Or can I send that to google places API somehow?
I think that the Google Maps API does what you need via their GEOCODING support.
http://code.google.com/apis/maps/documentation/javascript/v2/services.html#Geocoding
Since you've tagged the question under Android, I'm going to take a hit and assume that by "how do I use this with java", you actually mean how can I do this on the android platform.
Luckily, android provides the Geocoder APIs that you can use for geocoding addresses into lon/lat co-ordinates, by doing the following :
gc = new Geocoder(this); //create new geocoder instance
btnSearch.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String addressInput = adress.getText().toString(); //Get input text
try {
List<Address> foundAdresses = gc.getFromLocationName(addressInput, 5); //Search addresses
}
catch (Exception e) {
//@todo: Show error message
}
}
});
(above quoted from AndDev tutorial)
Once you've got the lon/lats, you can create a GeoPoint and slap them on a map, link here on how to do that.
精彩评论