I'm trying sample code for getting location using gps service.bt not gettong location.
Below is my code.-
public class MainActivity extends Activity implements LocationListener{
Location mLocation;
LocationManager mManager;
LocationListener mlistener;
Geocoder mcoder;
Context context;
TextView txtLat;
String lat;
String provider;
protected String latitude,longitude;
protected boolean gps_enabled,network_enabled;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
txtLat = (TextView) findViewById(R.id.tv);
}
public void getMyLocation(){
String addressString = "";
final Geocoder gc = new Geocoder(this, Locale.getDefault());
try
{
final List<Address> addresses = gc.getFromLocation(18.5203, 73.8567, 4);
final StringBuilder sb = new StringBuilder();
System.out.println("location..."+sb);
if ( addresses.size() > 0 )
{
final Address address = addresses.get(0);
for ( int i = 0; i < address.getMaxAddressLineIndex(); i++ )
{
sb.append(address.getAddressLine(i)).append("\n");
}
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
}
addressString = sb.toString();
}
catch ( final IOException e )
{
}
txtLat.setText("Your Current Position is:\n" +
"\n" + addressString);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onLocationChanged(Location location) {
getMyLocation();
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
Your code just needs some minor changes.
You must implement all methods of the listener to understand if the provider is available, if any is built into the device and if you can expect Location updates anyway.
In getMyLocation() you call the Geocoder.getFromLocation() with hardcoded latitude and longitude. Is this for debugging purposes?
Then there's a System.println() of a newly created , empty StringBuilder. If you want to print something out it's better to use Log.d().
And finally - if everything else works, but you still get no address in the textview - then try to Toast the address. It has less possibilities to go wrong but you need to stare on the screen as the message disappears after a second.
My guess here is, that your Emulator has no GPS configured or you do not get updates - either because there's no satellite or you simply do not wait long enough for satellite connections.
Related
i'm trying to develop application with a gps that can know if i arrive at or leave a specific place.
I.E if i am at home so, the application know that and if i leaving my home the application know that too. or if i want to set the radius of my home. but i think the problem is that when i trying to running the appliction and search places every x time it could kill my battery.
what is the best solution for that action? should i using services too?
here is the class i made to get the place and the coordinates:
public class LocationMap extends Service implements LocationListener {
public static final String LOG = "locationLogger";
Context context;
LocationManager manager;
Location location;
public static final int REFRESH = 1000*1;
public static final int DISTANCE = 1*1;
double lat,lng;
boolean isGps,isWiFi;
public LocationMap(Context context) {
this.context = context;
getLocation();
}
private Location getLocation(){
try {
manager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER,REFRESH,DISTANCE,this);
//Check who is on WiFi or GPS
isWiFi = manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);Log.d(LOG, "Wifi?="+isWiFi);
isGps = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);Log.d(LOG, "Gps?="+isGps);
Log.d(LOG, "manager is not null?="+manager);
if (manager != null) {
if(isGps){
Log.d(LOG, "get last location from Gps");
location = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}else
if(isWiFi){
Log.d(LOG, "get last location from WiFi");
location = manager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
if (location != null) {
lat = location.getLatitude();
lng = location.getLongitude();
Log.d(LOG, "lat="+lat +" lng="+lng);
}
}
} catch (Exception e) {
}
return location;
}
public String getPlace(){
String placeName = "No place found, check your gps setting";
try {
Geocoder geocoder = new Geocoder(context);
List<Address> address =geocoder.getFromLocation(getLat(), getLng(), 1);
String country = address.get(0).getCountryName();
String city = address.get(0).getLocality();
String street = address.get(0).getAddressLine(0);
placeName = country+", "+city+", "+street;
} catch (IOException e) {
e.printStackTrace();
}
return placeName;
}
public double getLng(){
return lng;
}
public double getLat() {
return lat;
}
#Override
public void onLocationChanged(Location location) {
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
sorry about my english. hope you understand me :)
That depends on your accuracy needed.
If the desired range is about 1 - 3km then there is a battery saving solution, I will not further explain here. (Using the devices Network locationg procider)
For accuracy much better there is no way around using GPS always on,
which at my iphone 4 lasts about 8 hours.
Detection if arrival is simply done via entering inside a circle, defined by lat,lon, radius.
Inside circle is calculated by:
boolean isInside = currentLocation.distanceTo(circleCenterLongitude, circleCenterLatitude) < radiusMeters.
I tracked the gps with the following code, But How to get notified If the gps tracker reaches that location ...
Capture.java
public class Capture extends Activity implements LocationListener{
Button btnNWShowLocation,btnsave;
TextView etlat,etlng,alreadyposted,t3,t4,t5;
EditText etplace;
String state1,state2;
protected String v1, v2, v3;
JSONParser jsonParser = new JSONParser();
JSONArray jsonarray;
ArrayList<HashMap<String,String>> arraylist;
JSONObject jsonobject;
String TAG_SUCCESS="success";
double latitude,longitude;
boolean isGPSEnabled = false;
boolean isNetworkEnabled = false;
double lat1,lng1;
String lat2,lng2;
String providernet,speed1,accuracy1;
float speed,accuracy;
Location location;
public LocationManager locationManager;
String provider;
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ThreadPolicy tp = ThreadPolicy.LAX;
StrictMode.setThreadPolicy(tp);
btnsave = (Button) findViewById(R.id.buttonsave);
etlat=(TextView)findViewById(R.id.textlatitude);
etlng=(TextView)findViewById(R.id.textlongitude);
alreadyposted=(TextView)findViewById(R.id.alreadyposted);
etplace=(EditText)findViewById(R.id.editplace);
t3=(TextView)findViewById(R.id.provider);
t4=(TextView)findViewById(R.id.speed);
t5=(TextView)findViewById(R.id.accuracyset);
alreadyposted.setVisibility(View.INVISIBLE);
locationManager = (LocationManager)Capture.this.getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the locatioin provider -> use
// default
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setCostAllowed(false);
provider = locationManager.getBestProvider(criteria,false);
Location location = locationManager.getLastKnownLocation(provider);
//Initialize the location fields
if (location!= null){
onLocationChanged(location);
latitude = location.getLatitude();
longitude =location.getLongitude();
} else {
Toast.makeText(getApplicationContext(), "Not available", Toast.LENGTH_SHORT).show();
}
btnsave.setOnClickListener(new View.OnClickListener() {
protected ArrayList<NameValuePair> parameters;
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
parameters = new ArrayList<NameValuePair>();
v1 = etlat.getText().toString();
v2 = etlng.getText().toString();
v3 = etplace.getText().toString();
arraylist = new ArrayList<HashMap<String, String>>();
// Retrieve JSON Objects from the given URL address
jsonobject = JSONfunctions
.getJSONfromURL("http://placementreadyguarantee.com/android/gps_tracking/Jsoncheckcapture.php?latitude="+v1+"&longitude="+v2);
try {
// Locate the array name in JSON
int success = jsonobject.getInt(TAG_SUCCESS);
if(success==1){
alreadyposted.setVisibility(View.VISIBLE);
}
else{
NameValuePair latitudejson = new BasicNameValuePair("latitude",v1);
NameValuePair longitudejson = new BasicNameValuePair("longitude",v2);
NameValuePair placejson = new BasicNameValuePair("place",v3);
parameters.add(latitudejson);
parameters.add(longitudejson);
parameters.add(placejson);
try {
JSONObject json =jsonParser.makeHttpRequest("http://placementreadyguarantee.com/android/gps_tracking/captureupload.php?latitude="
+URLEncoder.encode(v1,"UTF-8")
+"&longitude="
+URLEncoder.encode(v2,"UTF-8")
+"&place="
+URLEncoder.encode(v3,"UTF-8"),
"POST",parameters);
} catch (UnsupportedEncodingException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
alreadyposted.setVisibility(View.INVISIBLE);
}
}catch(Exception e){
e.printStackTrace();
}
}
});
}
/*Request updates at startup */
#Override
protected void onResume() {
super.onResume();
locationManager.requestLocationUpdates(provider,400,1,this);
//getting gps
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(isGPSEnabled){
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,400,1,this);
}
else if(isNetworkEnabled){
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,400,1,this);
}
}
/* Remove the locationlistener updates when Activity is paused */
#Override
protected void onPause(){
super.onPause();
//locationManager.removeUpdates(this);
locationManager.requestLocationUpdates(provider,400,1,this);
//getting gps
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(isGPSEnabled){
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,400,1,this);
}
else if(isNetworkEnabled){
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,400,1,this);
}
}
#Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
lat1=location.getLatitude();
lng1=location.getLongitude();
providernet=location.getProvider();
speed=location.getSpeed();
accuracy=location.getAccuracy();
accuracy1=Float.toString(accuracy);
speed1=Float.toString(speed);
lat2=Double.toString(lat1);
lng2=Double.toString(lng1);
etlat.setText(lat2);
etlng.setText(lng2);
t3.setText(providernet);
t4.setText(speed1);
t5.setText(accuracy1);
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
Toast.makeText(this, "Disabled provider " + provider,
Toast.LENGTH_SHORT).show();
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
Toast.makeText(this, "Enabled new provider " + provider,
Toast.LENGTH_SHORT).show();
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
In this i used json to store the latitude and longitude in mysql database(which is in my server space).
By clicking on button it saved current latitude and longitude in database .
Now i need to Do more , with this if the device reached that already saved place or around 10 meters or 20 meteers it send notification , or storing in database like that anything i need to do .
Thanks in advance . :)
i'm new to android ,I am try to get my current location address.my code is working but value of the text box is refreshing time to time. how i stop it...
this is my code..
public class MylocMainActivity extends Activity {
String lat="", lon="";
String ret= "" ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myloc_main);
//button click done
Button btnLocation = (Button)findViewById(R.id.btn_done);
btnLocation.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
location();
Log.d("OnClick","Passed");
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.myloc_main, menu);
return true;
}
public void location()
{
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) MylocMainActivity.this.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the network location provider.
lat = Double.toString(location.getLatitude());
lon = Double.toString(location.getLongitude());
TextView tv = (TextView) findViewById(R.id.tv_location);
tv.setText("Your Location is:" + lat + "--" + lon);
tv.setText(GetAddress(lat, lon));
Intent i = new Intent(MylocMainActivity.this,MainActivity.class);
i.putExtra("clist",ret.toString());
startActivity(i);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}
// get the address
public String GetAddress(String lat, String lon)
{
Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);
try {
List<Address> addresses = geocoder.getFromLocation(Double.parseDouble(lat), Double.parseDouble(lon), 1);
if(addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("Address:\n");
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
ret = strReturnedAddress.toString();
}
else{
ret = "No Address returned!";
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
ret = "Can't get Address!";
}
return ret;
}
}
........Main Activity class.............
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent startbuttonintent = getIntent();
String conlist = null;
conlist = startbuttonintent.getStringExtra("clist");
TextView name = (TextView) findViewById(R.id.family_Text);
name.setText(conlist);
Button btn = (Button)findViewById(R.id.btn_location);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,MylocMainActivity.class);
startActivity(i);
// TODO Auto-generated method stub
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Each time the location changes it changes the content of the textview although the content might not have actually changed due to number precision.
Try this or something similar with setting the textview:
public void onLocationChanged(Location location)
{
// Called when a new location is found by the network location provider.
lat = Double.toString(location.getLatitude());
lon = Double.toString(location.getLongitude());
TextView tv = (TextView) findViewById(R.id.tv_location);
if(!tv.getText().equals(GetAddress(lat, lon)))
{
tv.setText("Your Location is:" + lat + "--" + lon);
tv.setText(GetAddress(lat, lon));
}
Intent i = new Intent(MylocMainActivity.this,MainActivity.class);
i.putExtra("clist",ret.toString());
startActivity(i);
}
you could store the Location from onLocationChanged in an Location value (mLocation).
every time the location changes you check
if (mLocation != null) { // do something }
I'm trying to make a weather app that uses Geocoder to get the current city, and then uses AsyncTask to get weather data from an api and then parse it. But when I input the current city into the AsyncTask execute() method, my app crashes:
private double latitude;
private double longitude;
String address;
LocationManager lm;
LocationListener ll;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
address = getAddress(latitude, longitude); // getAddress() is below
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
ll = new myLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}
private class myLocationListener implements LocationListener {
#Override
public void onLocationChanged(android.location.Location location) {
latitude = location.getLatitude();
longitude = location.getLongitude();
String address = getAddress(latitude, longitude);
Task task = new Task(); // Task extends AsyncTask
task.execute(new String[] { address });
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
public String getAddress(double lat, double lon) {
Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);
String ret = "";
try {
List<Address> addresses = geocoder.getFromLocation(
lat, lon, 10);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuffer str = new StringBuffer();
str.append(returnedAddress.getLocality());
str.append(",");
str.append(returnedAddress.getCountryName());
ret = str.toString();
} else {
ret = "No Address returned!";
}
} catch (IOException e) { // TODO Auto-generated catch block
e.printStackTrace();
ret = "Can't get Address!";
}
return ret;
}
I know for a fact that my getAddress() method works like it's supposed to. When I hardcode a city and state into the address field, it works like a charm. However, when I call my getAddress() method and set it to address, and then input it into execute(), the app crashes and it says that getFromLocation() returned null. Why is this happening? Is it the order of my code? Thank you for all answers in advance.
Make sure your GPS is enabled and you are not testing from the emulator. The provider will return null if it is not enabled as per the documentation. Since you need the current location and probably you do not want updates I will recommend you use requestSingleUpdate(). A better option will be to use the new LocationClient Class that is part of Google Services; its fused provider gets the best Location available for you.
I wrote a program to show my current location, Address etc in android phone. The API used is Android 2.2. Previously it worked fine in a MTS CDMA phone. It had an API of Android 2.3. It also works fine in emulator. Now. I have bought a Sony Ericsson Xperia Minipro and it also has Android 2.3. But the program will run on it. But the edit texts will not show anything. I use edit texts to display the values. They are not updated by the program at all. What can be the problem? Same program works fine in emulator and it shows location! Please help. I can paste the code below
public class TravelGuide extends Activity {
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES=1;
private static final long MINIMUM_TIME_BETWEEN_UPDATES=1000;
StringBuilder strReturnedAddress;
List<Address> addresses;
protected LocationManager locationManager;
static String videoId;
Double lat;
Double longd;
Address returnedAddress;
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
//Double latitude = location.getLatitude();
//Double longitude = location.getLongitude();
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
};
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES,
MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,new MyLocationListener());
showCurrentLocation();
}
public void showCurrentLocation()
{
Location location=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location!=null)
{
TextView myLatitude = (TextView)findViewById(R.id.mylatitude);
TextView myLongitude = (TextView)findViewById(R.id.mylongitude);
TextView myAddress = (TextView)findViewById(R.id.myaddress);
String message=String.format("currentLocation\n Longitude:%1$s \n Latitude:%2$s",location.getLongitude(),location.getLatitude());
Toast.makeText(TravelGuide.this,message,Toast.LENGTH_LONG).show();
myLatitude.setText("Latitude: " + String.valueOf(location.getLatitude()));
myLongitude.setText("Longitude: " + String.valueOf(location.getLongitude()));
Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);
try {
List<Address> addresses = geocoder.getFromLocation(Double.valueOf(location.getLatitude()),
Double.valueOf(location.getLongitude()), 1);
if(addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("Address:\n");
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
videoId = (returnedAddress.getAddressLine(1)).toString();
//sendAddress(videoId);
myAddress.setText(strReturnedAddress.toString());
}
else{
myAddress.setText("No Address returned!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
//test = "kovalam";
myAddress.setText("Canont get Address!");
}
}
}
public class MyLocationListener implements LocationListener
{
//private final Context MyLocationListener = null;
//double LATITUDE;
//double LONGITUDE;
TextView myLatitude;
TextView myLongitude;
TextView myAddress;
public void onLocationChanged(Location location)
{
//Context context = null;
myLatitude = (TextView)findViewById(R.id.mylatitude);
myLongitude = (TextView)findViewById(R.id.mylongitude);
myAddress = (TextView)findViewById(R.id.myaddress);
//String message=String.format("new Location\n Longitude:%1$s \n Latitude:%2$s",
//location.getLongitude(),location.getLatitude());
//Toast.makeText(TouristGuideActivity.this,message,Toast.LENGTH_LONG).show();
myLatitude.setText("Latitude: " + String.valueOf(location.getLatitude()));
myLongitude.setText("Longitude: " + String.valueOf(location.getLongitude()));
Geocoder geocoder = new Geocoder(TravelGuide.this, Locale.ENGLISH);
try {
List<Address> addresses = geocoder.getFromLocation(Double.valueOf(location.getLatitude()),
Double.valueOf(location.getLongitude()), 1);
if(addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("Address:\n");
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
videoId = (returnedAddress.getAddressLine(1)).toString();
//sendAddress(videoId);
//myAddress.setText(strReturnedAddress.toString());
myAddress.setText("Hello");
}
else{
myAddress.setText("No Address returned!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
myAddress.setText("Canont get Address!");
}
}
public void onStatusChanged(String s, int i, Bundle b)
{
//Toast.makeText(TouristGuideActivity.this,"Provider status changed",Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String s)
{
Toast.makeText(TravelGuide.this,"Provider disabled by the user. GPS turned off",
Toast.LENGTH_LONG).show();
}
public void onProviderEnabled(String s)
{
Toast.makeText(TravelGuide.this,"Provider enabled by the user. GPS turned on",
Toast.LENGTH_LONG).show();
}
}
}
you are getting locaton object null,try put log in else condition..and the reason is you are fetching last known location which in not available in that phone some how..
so if its true..
Go to this answer here implement that code to get current location...and it will work fine.
If you are using GPS Provider to get Location,Its found that Its not so accurate to return you location object,Network Provider is better option According to me.