Plz let me know why this code is not giving exact location.
Although,if i am sending obtained latitude and longitude on google map,then
it provides exact location..
private void Find_Current_LatLong() { try { appendLog("\n
</br>Find_Current_LatLong(); Called \n </br>");
txtstatus.setText("Wait....Locating Accident Place!");
//Find Latitude & Longitude locationManager =
(LocationManager)this.getSystemService(Context. LOCATION_SERVICE);
locationlistener = new LocationListener() { public void
onLocationChanged(Location location) {
locationManager.removeUpdates( locationlistener); updateLocation(location);
}
public void onStatusChanged( String provider, int status, Bundle extras) {
switch (status) { case LocationProvider.AVAILABLE: txtstatus.setText("GPS
available again\n"); break; case LocationProvider.OUT_OF_SERVICE:
txtstatus.setText("GPS out of service\n"); break; case
LocationProvider.TEMPORARILY_UNAVAILABLE: txtstatus.setText("GPS
temporarily unavailable\n"); break; } } public void
onProviderEnabled(String provider) { txtstatus.setText("GPS Enabled"); }
public void onProviderDisabled(String provider) { txtstatus.setText("GPS
Disabled"); } };
locationManager. requestLocationUpdates( LocationManager.GPS_PROVIDER,
1000, 50, locationlistener);
} catch(Exception e) { Toast.makeText(this,"Find_ Current_LatLong:
"+e.toString(), Toast.LENGTH_LONG).show(); appendLog("\n </br>Error in
Find_Current_LatLong" +e.toString() ); }
}
void updateLocation(Location location){ try { appendLog("\n </br>update
Location called \n </br>"); currentLocation = location; currentLatitude =
currentLocation.getLatitude(); currentLongitude =
currentLocation.getLongitude(); appendLog("\n </br>Lat long is: \n </br>"+
Double.toString(currentLatitude) +" "+ Double.toString(currentLongitude));
txtstatus.setText("Latitude & Longitude Found!"); getAddress();
if(location!=null) {
locationManager.removeUpdates( locationlistener); appendLog("\n
</br>Location Updater Removed \n </br>"); } } catch(Exception e) {
Toast.makeText(this,"Location Update Not Succeed!"+e.toString(),
Toast.LENGTH_LONG).show(); } }
protected void getAddress() { try{ appendLog("\n </br>
Get Address Called \n </br>"); txtstatus.setText("Converting GeoCordinate
To Address !"); appendLog("\n </br>GetAddress start finding Address \n
txtstatus.setText("Address Found!"); }
try { Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses1 = geocoder.getFromLocation(currentLatitude,
currentLongitude,1);
Address obj = addresses1.get(0); add = obj.getAddressLine(0);
add = add + "\n </br>" + obj.getCountryName(); add = add + "\n </br>" +
obj.getCountryCode(); add = add + "\n </br>" + obj.getAdminArea(); add =
add + "\n </br>" + obj.getPostalCode(); add = add + "\n </br>" +
obj.getSubAdminArea(); add = add + "\n </br>" + obj.getLocality(); add =
add + "\n </br>" + obj.getSubThoroughfare();
appendLog("\n </br>Address Found:"+ add + "\n </br>");
txtstatus.setText("Address Found!"); } catch (IOException e) { // TODO
Auto-generated catch block e.printStackTrace(); Toast.makeText(this,
e.getMessage(), Toast.LENGTH_SHORT).show(); }
}
if(Count<=0) { appendLog("\n </br>Count Set to 15 \n </br>"); Count=15;
appendLog("\n </br>Finishing Activity\n </br>"); finish(); } }
catch(Exception ex){
Toast.makeText(this,"getAddress :"+ex.toString(),
Toast.LENGTH_LONG).show(); } }
}
Plz help.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en