Monday, January 17, 2011

Map Services -- Local Search

You can use “Local search” to search business in given area, like search for café, restaurant etc.  It has similar usage as Geocoding.
The following example searches for café around -31.948275, 115.857562.

public class MapLocalSearchMIDP 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.GOOGLEMAP);
        Display.getDisplay(this).setCurrent(canvas);
    }

    public void commandAction(Command c, Displayable d) {
        if (c == mapFindAddressCommand) {
            String name = " cafe";
            GeoLatLng screenCenter = map.getScreenCenter();
            map.getLocations(name, 0, screenCenter, map.getScreenBounds(screenCenter));
        }
    }

    public void done(String query, MapPoint[] result) {
        if (result != null) {
            map.panTo(result[0].getPoint());
            for (int i = 0; i < result.length; i++) {
                System.out.println(result[i].objectNote);
            }
        }
    }
}





Local search method:
public void getLocations(String address,int start,GeoLatLng center,GeoBounds bound, IGeocodingListener listener);
search based on the center and boundary. Local search can return mulptile results and can be called multiple time, start gives the start index of the result. you can specify the number of each return ,for google,each time is 4.
The above example’s output is as following (maybe different in your case).
Cafe Cafe (08) 9388 9800 (08) 9388 7800
The Moon Cafe (08) 9328 7474
tiger, tiger coffee bar (08) 9322 8055
Monte Fiore Cafe Restaurant (08) 9227 9898

No comments:

Post a Comment