c# - Latitude isn't accurately but Long is accurately - Android device -


I try to get my lat long from Android device with GPS.

My code is:

  Location Manager LM, Location Manager; Location L; TextView LT, LN; LM = (LocationManager) this.getSystemService (Context.LOCATION_SERVICE); Lm.requestLocationUpdates (LocationManager.GPS_PROVIDER, 0, 0, this); L = lm.getLastKnownLocation (LocationManager.GPS_PROVIDER); UpdateWithNewLocation (L); Private zeros update with new location (location location) {string latLongString = "unknown"; String address string = "no address found"; Decimalf df = new passphrase ("## 00"); If (place! = Null) {double lat = location.getLatitude (); Double LNG = location.getLongitude (); LatLongString = "Lat:" + df.format (lat) + "\ n Long:" + df.format (lng); Geocoder GC = new GeoCoder (main activity. This, local.get default ()); {List & lt; Address & gt; Addresses = gc.getFromLocation (lat, lng, 1); If (addresses.size () == 1) {addressString = ""; Address address = addresses.get (0); AddressString = addressString + address.getAddressLine (0) + "\ n"; (Int i = 0; i & lt; address.getMaxAddressLineIndex (); i ++) {addressString = addressString + address.getAddressLine (i) + "\ n"; } AddressString = addressString + address.getLocality () + "\ n"; AddressString = addressString + address.getPostalCode () + "\ n"; addressString = addressString + address.getCountryName () + "\ n"; }} Hold (IOException ioe) {Log.e ("GeoCoder IOException exception:", ioe.getMessage ()); }} Accurity.setText ("Your current state is: \ n" + latLongString + "\ n" + address string); Ln.setText ("+" + LNG); Lt.setText ("+ +"); }}   

I'm sending my latitude, the C # code map (dynamic data display) and pointing it to the map. This code is wrong by the code (it is close to my location, but is not correct) Although with the address string I have found the building and the correct address of city and country. The address string GPS and the wave gets from the GPS for a long time, so why is it also correct?

  addresses = gc.getFromLocation (lat, lng, 1);            div class = "post-text" itemprop = "text"> 

lm.getlastlocation does not always provide accurate update for long periods of time. U needs to use a location request object in requestlocationupdate (locationrequest, location_listener) and use late-length instead provides the location listener, it provides accurate results. Sharing the code below:

  Private location line mlocationrequest; // location listener locale loc_listener = new location listener () {@Override changed location to public zero (location ARB0) {if (arg0! = Null) {lat = arg0.getLatitude (); Lng = arg0.getLongitude (); Tm = arg0.getTime (); }}};   

Mlocationrequest.setPriority (LocationRequest.PRIORITY_HIGH_ACCURACY); Mlocationrequest.setFastestInterval (1000); Mlocationrequest.setInterval (10000);

then the simple pass

  mlocationclient.requestLocationUpdates (mlocationrequest, loc_listener);    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -