1 package 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 19 import android.location.Address; 20 import android.location.Geocoder; 21 import android.test.AndroidTestCase; 22 import android.test.suitebuilder.annotation.Suppress; 23 import android.util.Log; 24 25 import java.io.IOException; 26 import java.util.HashSet; 27 import java.util.Locale; 28 import java.util.Set; 29 import java.util.List; 30 31 @Suppress 32 public 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