i'm new into android, please help.
I'm trying to run onLocationChanged(Location location)
inside a Service.
so that it will make marker all the time until stop button is clicked.
public class MyService extends Service implements LocationListener {
// variable peta
GoogleApiClient mGoogleApiClient;
LocationRequest mLocationRequest;
private GoogleMap mMap;
Location location;
// parameter untuk di masukin ke database
TextView tvlattitude;
TextView tvlongitude;
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
onLocationChanged(location);
// Let it continue running until it is stopped.
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
@Override
public void onLocationChanged(Location location) {
double lattitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))
.position(latLng)
.title("Kamu disini"));
tvlattitude.setText(""+lattitude);
tvlongitude.setText(""+longitude);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}
this is i have tried, but its said, Null Pointer Exception on location
what cause it? need help.