Last active
January 23, 2019 10:01
-
-
Save nadar71/dac390a7b97222cc5d50c627ec54deb3 to your computer and use it in GitHub Desktop.
Set position in a map by long pressing. Used in Android, google maps v2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set position by long press | |
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() { | |
@Override | |
public void onMapLongClick(LatLng latLng) { | |
// First check if myMarker is null | |
if (myManualPositionMarker == null) { | |
// Marker was not set yet. Add marker: | |
myManualPositionMarker = mMap.addMarker(new MarkerOptions() | |
.position(latLng) | |
.title("My positions") | |
.snippet("Your marker snippet")); | |
} else { | |
// Marker already exists, just update it's position | |
myManualPositionMarker.setPosition(latLng); | |
} | |
myManualPositionMarker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment