GeocoderTest.java revision 1a44d5dcabc18cd5ef111f732ccff91683a1a093
1package android.location;
2
3/*
4 * Copyright (C) 2007 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19import android.location.Address;
20import android.location.Geocoder;
21import android.test.AndroidTestCase;
22import android.test.suitebuilder.annotation.Suppress;
23import android.util.Log;
24
25import java.io.IOException;
26import java.util.HashSet;
27import java.util.Locale;
28import java.util.Set;
29import java.util.List;
30
31@Suppress
32public class GeocoderTest extends AndroidTestCase {
33
34    public void testGeocoder() throws Exception {
35        Locale locale = new Locale("en", "us");
36        Geocoder g = new Geocoder(mContext, locale);
37
38        List<Address> addresses1 = g.getFromLocation(37.435067, -122.166767, 2);
39        assertNotNull(addresses1);
40        assertEquals(1, addresses1.size());
41
42        Address addr = addresses1.get(0);
43        assertEquals("94305", addr.getFeatureName());
44        assertEquals("Palo Alto, CA 94305", addr.getAddressLine(0));
45        assertEquals("USA", addr.getAddressLine(1));
46        assertEquals("94305", addr.getPostalCode());
47        assertFalse(Math.abs(addr.getLatitude() - 37.4240385) > 0.1);
48
49        List<Address> addresses2 = g.getFromLocationName("San Francisco, CA", 1);
50        assertNotNull(addresses2);
51        assertEquals(1, addresses2.size());
52
53        addr = addresses2.get(0);
54        assertEquals("San Francisco", addr.getFeatureName());
55        assertEquals("San Francisco, CA", addr.getAddressLine(0));
56        assertEquals("United States", addr.getAddressLine(1));
57        assertEquals("San Francisco", addr.getLocality());
58        assertEquals("CA", addr.getAdminArea());
59        assertEquals(null, addr.getPostalCode());
60
61        assertFalse(Math.abs(addr.getLatitude() - 37.77916) > 0.1);
62
63    }
64}
65