free web page hit counter
Friday Jan 05, 2007

Netbeans 5.5 Tip: Create a Webservice client to find Latitude & Longitude of your city

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

  • Using Netbeans 5.5 IDE, create a General Java Application project called LocationService
  • Right click on the project select New -> New Webservice Client
  • In the New Webservice Client dialog, select WSDL URL and provide http://terraserver.microsoft.com/TerraService2.asmx?WSDL
  • Also specify "locationsvc" as package name

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

Comments:

Hi Winston,
If you're more into RESTful stuff, there's Google's equivalent: http://blogs.sun.com/alexismp/entry/mashup_explanation_part_i

Posted by A` on January 06, 2007 at 04:17 AM PST #

It's so cool...

Posted by cpark on January 06, 2007 at 11:06 AM PST #

Hi, this seems like a great tutorial, but I can't drag and drop the method. When I try typing locationsvc.TerraService service = new locationsvc.TerraService(); NetBeans creates a slew of empty methods, non of which are mentioned here. It seems like a simple task, yet somehow it is beyond me. What am I doing wrong???

Posted by Eric on January 12, 2007 at 05:23 PM PST #

hkv,;

Posted by 193.190.255.61 on March 06, 2007 at 05:13 AM PST #

Your example worked great! However, when I try a different Web Service, specifically one created by someone using .NET, I get the following error: [WARNING] src-resolve.4.2: Error resolving component 's:schema'. It was detected that 's:schema' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document ... Apparently, I'm not the only one having a problem. See: http://forums.java.net/jive/message.jspa?messageID=201229 If you can guide me on how to fix this problem without changing the Web Service (since I didn't write it), I would appreciate it. Thank you.

Posted by Sam Lalani on March 25, 2007 at 05:28 PM PDT #

Hi,
I am trying to write a Java wbservice client for a .NET webservice. The .NET service required a Ticket number and a logon parameter to be passed in for Authentication.

I am unable to write this code. I am using Netbeans and am not able to create a Stub for my service. Typecasting does not work either. Please help......

Posted by Sucheta Lele on September 17, 2007 at 01:19 PM PDT #

comment

Posted by 88.155.25.119 on September 18, 2007 at 01:15 PM PDT #

Hi,

I am trying to access .Net webservice through Java client using Netbeans 6.0. Initially everything worked correctly. Ysterday I re installed my websrvice again after which I started gtting an error "Operation Undefined" for a particular operation though the operation is present in the wsdl and corresponding java class is formed.

Could anyone help me out? I am new to .net.

Thanks & Regards,
Sneha

Posted by Sneha on February 19, 2008 at 02:04 AM PST #

I have a GPS system on my car bought from http://www.lweshop.com/ and it really has helped enormously in finding new locations. I found this blog most interesting as I didn’t realize all of the wide range of applications out there today for GPS technology

Posted by Car GPS on December 21, 2008 at 06:07 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed