Using Netbeans 5.5 IDE, it is as easy as 1..2..3 to develop a Webservice client to find the Latitude and Longitude of your city. The webservice I used here is from Microsoft Terra Server called TerraService.
Here are the steps
The TerraService Webservice client will be added to the project as shown below.
Drag and drop the method ConvertPlaceToLonLatPt from the webservice client on to the main() method of Main.java. Necessary code will be added. Modify as shown below to display the location (blue lines are modified by me)
try { // Call Web Service Operation
locationsvc.TerraService service = new locationsvc.TerraService();
locationsvc.TerraServiceSoap port = service.getTerraServiceSoap();
// TODO initialize WS operation arguments here
locationsvc.Place place = new locationsvc.Place();
place.setCity("Menlo Park");
place.setState("California");
place.setCountry("United States");
// TODO process result here
locationsvc.LonLatPt result = port.convertPlaceToLonLatPt(place);
System.out.println("City: " + place.getCity() + ", " +
place.getState() + ", " + place.getCountry());
System.out.println("Latitude = " + result.getLat() + " Longitude: "
+ result.getLon());
} catch (Exception ex) {
// TODO handle custom exceptions here
}
Compile and run the application. Bingo!, the result is the Latitude and Longitude of your city.
run:
City: Menlo Park, California, United States
Latitude = 37.45000076293945 Longitude: -122.16999816894531 BUILD SUCCESSFUL (total time: 3 second