/** * when map is long clicked * * @param callback */ public void whenMapLongClick(final ClickCallback callback) { map.setOnMapLongClickListener(new OnMapLongClickListener() { @Override public void onMapLongClick(LatLng latLng) { callback.clicked(map, latLng); } }); }
@Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; mMap.clear(); Double lat = Double.parseDouble(latPlace); Double lon = Double.parseDouble(longPlace); LatLng currentPlace = new LatLng(lat, lon); mMap.addMarker(new MarkerOptions() .position(currentPlace) .title(namePlace) .icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory .HUE_BLUE))); mMap.moveCamera(CameraUpdateFactory.zoomTo(10)); mMap.moveCamera(CameraUpdateFactory.newLatLng(currentPlace)); mMap.setOnMapLongClickListener(new OnMapLongClickListener() { @Override public void onMapLongClick(LatLng arg0) { mMap.addMarker(new MarkerOptions() .position(arg0) .title("new location") .icon(BitmapDescriptorFactory .defaultMarker(BitmapDescriptorFactory.HUE_BLUE))); Double lati = (arg0.latitude); Double loni = (arg0.longitude); String aLatPlace = lati.toString(); String aLongPlace = loni.toString(); Geocoder myGeo = new Geocoder(getApplicationContext(), Locale.getDefault()); try { List<Address> myAddresses = myGeo.getFromLocation(lati, loni, 1); if (myAddresses != null && myAddresses.size() > 0) { // FOR TESTING //Log.i("WJH", myAddresses.get(0).toString()); myNewLocal = myAddresses.get(0).getAddressLine(0) + ", " + myAddresses.get(0).getAddressLine(1); } else { myNewLocal = ""; } } catch (IOException e) { e.printStackTrace(); } Intent returnIntent = getIntent(); returnIntent.putExtra("anamePlace",myNewLocal); returnIntent.putExtra("alatPlace",aLatPlace); returnIntent.putExtra("alongPlace",aLongPlace); setResult(Activity.RESULT_OK,returnIntent); finish(); } }); }
@Override public final void setOnMapLongClickListener(OnMapLongClickListener listener) { map.setOnMapLongClickListener(listener); }
void setOnMapLongClickListener(OnMapLongClickListener listener);