Search code examples
javaandroidgpsonclicklocationlistener

Android onClick jump to current location and activate LocationListener


This was created with guidance from Kaj (below)

Figured my problem out, but this may be useful for someone else looking to jump to current users location:

boolean touched = false;

if(touched == false){
    mapController.animateTo(point);
}

myLocationBtn.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        touched = false;
    }
});

@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    {   
//---when user lifts his finger---
if (event.getAction() == 1) {
    touched = true;
     }
return false;
}

Solution

  • Your onClick should say touched = "no"; and not String touched = "no";. Btw, it's probably better to change it to a boolean, so that you have true/false, instead of having strings. You should normally not compare strings with ==, use string.equals(anotherString) instead.