Address query or Geocoding, is to find an address’s latitude and longitude according to its name (like James St , Perth ).
The following examples show how to use the Geocoding services with ServerMap, it querys for 7 Fairway, Crawley , Australia . And then display the map in that area.
| public class MapGeocodingMIDP extends MapDemoMIDP implements CommandListener, IGeocodingListener { private Command mapFindAddressCommand = new Command("Find Address", Command.OK, 1); public void startApp() { init(); canvas.addCommand(mapFindAddressCommand); map.setGeocodingListener(this); canvas.setCommandListener(this); GeoLatLng center = new GeoLatLng(-31.948275, 115.857562); map.setCenter(center, 13, MapType.MICROSOFTMAP); Display.getDisplay(this).setCurrent(canvas); } public void commandAction(Command c, Displayable d) { if (c == mapFindAddressCommand) { String name = "7 Fairway, } } public void done(String query, MapPoint[] result) { if (result != null) { map.panTo(result[0].getPoint()); } } } |
All results returned by map service asynchronously.
Before call RasterMap.getLocation (address), a callback (listener) can be set with RasterMap.setGeocodingListener; the callback will be called when service returns.
The listener methods is defined as
public void done(String query,MapPoint[] result).
If the search has return , the result is the array of all returned result. the examples move the map to the first address found.

No comments:
Post a Comment