GeocodeProvider.java revision ccb4c318aa5150ba49b7e7878d20b4787d6bf723
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.location.provider;
18
19import android.os.IBinder;
20
21import android.location.Address;
22import android.location.GeocoderParams;
23import android.location.IGeocodeProvider;
24
25import java.util.List;
26
27/**
28 * Base class for geocode providers implemented as unbundled services.
29 *
30 * <p>Geocode providers can be implemented as services and return the result of
31 * {@link GeocodeProvider#getBinder()} in its getBinder() method.
32 *
33 * <p>IMPORTANT: This class is effectively a public API for unbundled
34 * applications, and must remain API stable. See README.txt in the root
35 * of this package for more information.
36 */
37public abstract class GeocodeProvider {
38
39    private IGeocodeProvider.Stub mProvider = new IGeocodeProvider.Stub() {
40        public String getFromLocation(double latitude, double longitude, int maxResults,
41                GeocoderParams params, List<Address> addrs) {
42            return GeocodeProvider.this.onGetFromLocation(latitude, longitude, maxResults,
43                    params, addrs);
44        }
45
46        public String getFromLocationName(String locationName,
47                double lowerLeftLatitude, double lowerLeftLongitude,
48                double upperRightLatitude, double upperRightLongitude, int maxResults,
49                GeocoderParams params, List<Address> addrs) {
50            return GeocodeProvider.this.onGetFromLocationName(locationName, lowerLeftLatitude,
51                    lowerLeftLongitude, upperRightLatitude, upperRightLongitude,
52                    maxResults, params, addrs);
53        }
54    };
55
56    /**
57     * This method is overridden to implement the
58     * {@link android.location.Geocoder#getFromLocation(double, double, int)} method.
59     * Classes implementing this method should not hold a reference to the params parameter.
60     */
61    public abstract String onGetFromLocation(double latitude, double longitude, int maxResults,
62            GeocoderParams params, List<Address> addrs);
63
64    /**
65     * This method is overridden to implement the
66     * {@link android.location.Geocoder#getFromLocationName(String, int, double, double, double, double)} method.
67     * Classes implementing this method should not hold a reference to the params parameter.
68     */
69    public abstract String onGetFromLocationName(String locationName,
70            double lowerLeftLatitude, double lowerLeftLongitude,
71            double upperRightLatitude, double upperRightLongitude, int maxResults,
72            GeocoderParams params, List<Address> addrs);
73
74    /**
75     * Returns the Binder interface for the geocode provider.
76     * This is intended to be used for the onBind() method of
77     * a service that implements a geocoder service.
78     *
79     * @return the IBinder instance for the provider
80     */
81    public IBinder getBinder() {
82        return mProvider;
83    }
84}
85