Listing 107 srccomcookbookgeocodingMyLocationjava

package com.cookbook.geocoding;

import; import java.util.List; import java.util.Locale;

import; import android.content.Context; import android.location.Address; import android.location.Criteria; import android.location.Geocoder; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.widget.TextView;

public class MyLocation extends Activity { LocationManager mLocationManager; Location mLocation; TextView tv;

^Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);


tv = (TextView) findViewById(;

mLocationManager = (LocationManager)


Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_LOW); String locationprovider =


mLocation =

mLocationManager.getLastKnownLocation(locationprovider); List<Address> addresses;

String myAddress="Seattle,WA"; Geocoder gc = new Geocoder(this); try {

addresses = gc.getFromLocationName(myAddress, 1); if(addresses != null) {

Address x = addresses.get(0);

StringBuilder mSB = new StringBuilder("Address:\n");

mSB.append("latitude: ").append(x.getLatitude()); mSB.append("\nlongitude: ").append(x.getLongitude()); tv.setText(mSB.toString());

} catch(IOException e) {


Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook

Post a comment