Code example for Geocoder

0
 
    private Geocoder geocoder;
 
    @Before 
    public void setUp() throws Exception { 
        geocoder = new Geocoder(new Activity());
    } 
 
    @Test 
    public void shouldRecordLastLocationName() throws Exception { 
        geocoder.getFromLocationName("731 Market St, San Francisco, CA 94103", 1);
        String lastLocationName = shadowOf(geocoder).getLastLocationName();
         
        assertEquals("731 Market St, San Francisco, CA 94103", lastLocationName);
    } 
 
    @Test 
    public void setsUpHasLocationInAddressFromLocationName() throws Exception { 
        shadowOf(geocoder).setSimulatedHasLatLong(true, true);
        Address address = geocoder.getFromLocationName("731 Market St, San Francisco, CA 94103", 1).get(0);
        assertTrue(address.hasLatitude());