Skip to content
Permalink
Browse files

#1303 some demo code to prove it works

  • Loading branch information...
spyhunter99 committed Apr 4, 2019
1 parent 0278752 commit 24924dfb160da76b0f9ee21471ca98ee6c700b13
@@ -1,9 +1,12 @@
package org.osmdroid.samplefragments.location;

import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.Toast;

import org.osmdroid.samplefragments.BaseSampleFragment;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;

@@ -20,21 +23,41 @@ public String getSampleTitle() {
}

@Override
public void addOverlays(){
public void addOverlays() {
super.addOverlays();

MyLocationOverlayWithClick overlay = new MyLocationOverlayWithClick(mMapView);
final MyLocationOverlayWithClick overlay = new MyLocationOverlayWithClick(mMapView);
overlay.enableFollowLocation();
overlay.enableMyLocation();
overlay.runOnFirstFix(new Runnable() {
@Override
public void run() {
Log.i(TAG, "I was ran on the first fix");
FragmentActivity activity = SampleMyLocationWithClick.this.getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
GeoPoint myLocation = overlay.getMyLocation();
if (myLocation != null)
Toast.makeText(SampleMyLocationWithClick.this.getContext(), "GPS fix acquired at " + myLocation.toDoubleString(), Toast.LENGTH_LONG).show();
else
Toast.makeText(SampleMyLocationWithClick.this.getContext(), "GPS fix acquired (null)", Toast.LENGTH_LONG).show();
}
});

}
});
mMapView.getOverlayManager().add(overlay);

}

public static class MyLocationOverlayWithClick extends MyLocationNewOverlay{
public static class MyLocationOverlayWithClick extends MyLocationNewOverlay {

public MyLocationOverlayWithClick(MapView mapView) {
super(mapView);
}

@Override
public boolean onSingleTapConfirmed(MotionEvent e, MapView map) {
if (getLastFix() != null)

0 comments on commit 24924df

Please sign in to comment.
You can’t perform that action at this time.