Guest User

Untitled

a guest
Jul 17th, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. LocationListener locLis=new LocationListener() {
  2.  
  3. @Override
  4. public void onStatusChanged(String provider, int status, Bundle extras) {}
  5. @Override
  6. public void onProviderEnabled(String provider) {}
  7. @Override
  8. public void onProviderDisabled(String provider) {}
  9. @Override
  10. public void onLocationChanged(Location location)
  11. {
  12. // TODO Auto-generated method stub
  13. Double lat=location.getLatitude();
  14. Double lon=location.getLongitude();
  15. Log.i("Latitude=="+lat,"=="+lon);
  16.  
  17. }
  18. };
  19. locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  20. locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER,0,0, locLis);
  21.  
  22. public class MyLocationListener implements LocationListener
  23. {
  24.  
  25. @Override
  26. public void onLocationChanged(Location loc)
  27.  
  28. {}
  29.  
  30. @Override
  31. public void onProviderDisabled(String provider)
  32. {}
  33. @Override
  34. public void onProviderEnabled(String provider)
  35. {}
  36. @Override
  37. public void onStatusChanged(String provider, int status, Bundle extras)
  38. {
  39.  
  40. }
  41. }
  42. mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  43. mlocListener = new MyLocationListener();
  44.  
  45. mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
  46.  
  47. List<String> providers = locationManager.getProviders(true);
  48. for (String provider : providers)
  49. {
  50. locationManager.requestLocationUpdates(provider, 1000, 0,new LocationListener()
  51. {
  52. public void onLocationChanged(Location location) {}
  53. public void onProviderDisabled(String provider){}
  54. public void onProviderEnabled(String provider){}
  55. public void onStatusChanged(String provider, int status,Bundle extras){}
  56. });
  57. Location location = locationManager.getLastKnownLocation(provider);
  58. if (location != null)
  59. {
  60. latitude = location.getLatitude();
  61. longitude = location.getLongitude();
  62. addr=ConvertPointToLocation(latitude,longitude);
  63. String temp_c=SendToUrl(addr);
  64.  
  65. }
  66. }
  67. }
  68.  
  69. public String ConvertPointToLocation(double pointlat,double pointlog) {
  70.  
  71. String address = "";
  72. Geocoder geoCoder = new Geocoder(con,
  73. Locale.getDefault());
  74. try {
  75. List<Address> addresses = geoCoder.getFromLocation(pointlat,pointlog, 1);
  76. if (addresses.size() > 0) {
  77. for (int index = 0; index < addresses.get(0)
  78. .getMaxAddressLineIndex(); index++)
  79. address += addresses.get(0).getAddressLine(index) + " ";
  80. }
  81. }
  82. catch (IOException e) {
  83. e.printStackTrace();
  84. }
  85. return address;
  86. }
Add Comment
Please, Sign In to add comment