18.3 MapPoint J2ME Clients With the Axis facade gateway, we have transformed the MapPoint Web Service to a wireless-friendly service while still preserving the benefits of SOAP Web Services. In fact, we can use any Web Services-compatible client to access MapPoint services through the Axis gateway. Those clients can be developed on almost all Microsoft platforms, all Java editions, script languages such as Perl and AppleScript, as well as many native C/C++ SOAP frameworks. In this section, we demonstrate two simple J2ME clients for driving directions.
18.3.1 CDC/PP and PersonalJava Clients Figure 18.2 demonstrates the driving directions client in action on a PocketPC device running Jeode PersonalJava VM. Thanks to the standard AWT library, the same client runs on CDC/FP/PP devices (e.g., IBM WebSphere Micro Edition's Personal Profile runtime) and standard J2SE desktops (e.g., Windows, Linux, and Mac OS) without modification.
![](/image/library/english/10153_18fig02.gif) Key code snippet that queries the Axis gateway service for directions and maps is shown in Listing 18.2.Listing 18.2. The CDC/PP driving directions client
public class AWTMap extends Frame implements WindowListener, ActionListener { private String endPointURL; private TextField fromStreet; private TextField fromCity; private TextField fromState; private TextField fromZip; private TextField toStreet; private TextField toCity; private TextField toState; private TextField toZip; private java.awt.List directionsList; private ClassMap cm; private Marshal md; // Other variables // Lists the driving directions private void listScreen (boolean newSearch) { try { if (newSearch) { SoapObject method = new SoapObject(", "getDirections"); // Use the SE version for standard JDK // Http methods HttpTransportSE rpc = new HttpTransportSE(endPointURL, "\"\"); rpc.setClassMap(cm); method.addProperty("in0", fromStreet.getText()); method.addProperty("in1", fromCity.getText()); method.addProperty("in2", fromState.getText()); method.addProperty("in3", fromZip.getText()); method.addProperty("in4", toStreet.getText()); method.addProperty("in5", toCity.getText()); method.addProperty("in6", toState.getText()); method.addProperty("in7", toZip.getText()); Vector v = (Vector) rpc.call (method); directionsList = new java.awt.List(10, false); directionsList.add("Overview Map"); for (int i = 0; i < v.size(); i++) { directionsList.add((String) v.elementAt(i)); } directionsList.setSize(200, 200); } Panel top = new Panel (); top.setLayout(new FlowLayout(FlowLayout.LEFT)); top.add(directionsList); Panel bottom = new Panel (); bottom.setLayout(new FlowLayout(FlowLayout.LEFT)); bottom.add(startOver); bottom.add(showMap); scroll.remove(content); content = new Panel (); content.setLayout(new BorderLayout()); content.add(top, BorderLayout.CENTER); content.add(bottom, BorderLayout.SOUTH); scroll.add(content); setVisible(true); } catch (Exception e) { e.printStackTrace(); } } private void mapScreen (int i) { try { ImageItem img; byte [] imgarray; SoapObject method = new SoapObject(", "getMap"); HttpTransportSE rpc = new HttpTransportSE(endPointURL, "\"\"); rpc.setClassMap(cm); method.addProperty("in0", new Integer(i)); method.addProperty("in1", new Integer(200)); method.addProperty("in2", new Integer(200)); imgarray = (byte []) rpc.call (method); img = new ImageItem(imgarray, 200, 200); Panel top = new Panel (); top.add(img); Panel bottom = new Panel (); bottom.add(startOver); bottom.add(showDirections); scroll.remove(content); content = new Panel (); content.setLayout(new BorderLayout()); content.add(top, BorderLayout.CENTER); content.add(bottom, BorderLayout.SOUTH); scroll.add(content); setVisible(true); } catch (Exception e) { e.printStackTrace(); } } // Other UI and event handling methods }
18.3.2 MIDP Clients Figure 18.3 shows the MIDP client in action in a MIDP v2.0 emulator. Since MapPoint supports only GIF image format rendering at this stage, but MIDP requires PNG format, driving maps are not yet available in the MIDP client. A quick fix would be to convert GIF images to PNG images inside the facade using the Java imaging API.
![](/image/library/english/10153_18fig03.gif) Complete source code and build scripts for both Java clients as well as for a .NET Compact Framework client are available for download from this book's Web site. |