How to find user current location latitude,longitude without touch event?I searched in internet but i get latitude,longitude only touch event.
Asked
Active
Viewed 825 times
2 Answers
3
I've answered to similar question of yours here. Take a look at that. It doesn't need the google maps.
public class LocationSampleActivity extends Activity implements OnInitListener
{
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView)this.findViewById(R.id.txtLocation);
tts = new TextToSpeech(this, this);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new mylocationlistener();
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll);
}
private class mylocationlistener implements LocationListener
{
@Override
public void onLocationChanged(Location location) {
if (location != null) {
Log.d("LOCATION CHANGED", location.getLatitude() + "");
Log.d("LOCATION CHANGED", location.getLongitude() + "");
String str = "\n CurrentLocation: "+
"\n Latitude: "+ location.getLatitude() +
"\n Longitude: " + location.getLongitude();
tv.append(str);
speak(location);
}
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(LocationSampleActivity.this,"Error onProviderDisabled",Toast.LENGTH_LONG).show();
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(LocationSampleActivity.this,"onProviderEnabled",Toast.LENGTH_LONG).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Toast.makeText(LocationSampleActivity.this,"onStatusChanged",Toast.LENGTH_LONG).show();
}
}
}
It will update your current location's latitude & longtitude into the TextView
without touch simply. Please add the important permission into your manifest file.
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

Community
- 1
- 1

Praveenkumar
- 24,084
- 23
- 95
- 173
-
Spk:It is working in emulator only.but i installed my real device it will not automatically get user current location. – Ram Aug 17 '12 at 04:30
1
use MyLocationOverlay for get current location.
MyLocationOverlay whereAmI = new MyLocationOverlay(this,mapview);
GeoPoint myLocationGeoPoint = whereAmI.getMyLocation();
float latitude = myLocationGeoPoint.getLatitudeE6() / 1E6;
float longitude = myLocationGeoPoint.getLongitudeE6() / 1E6;

RVG
- 3,538
- 4
- 37
- 64
-
-
if u get lat,long value from location, use this. int lat = (int) (location.getLatitude() * 1E6); int lng = (int) (location.getLongitude() * 1E6); – RVG Aug 17 '12 at 04:36
-
I added this point: positionOverlay.setLocation(location); Double geoLat=location.getLatitude()*1E6; Double geoLng=location.getLongitude()*1E6; GeoPoint point=new GeoPoint(geoLat.intValue(),geoLng.intValue()); – Ram Aug 17 '12 at 04:51