@Override public void setOnMarkerDragListener(final OnMapMarkerDragListener listener) { if (listener == null) { googleMap.setOnMarkerDragListener(null); return; } googleMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() { @Override public void onMarkerDragStart(Marker marker) { listener.onMapMarkerDragStart(marker); } @Override public void onMarkerDrag(Marker marker) { listener.onMapMarkerDrag(marker); } @Override public void onMarkerDragEnd(Marker marker) { listener.onMapMarkerDragEnd(marker); } }); }
@Override protected void startDemo() { mTextView = (TextView) findViewById(R.id.textView); getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8256, 151.2395), 10)); getMap().setOnMarkerDragListener(this); mMarkerA = getMap().addMarker(new MarkerOptions().position(new LatLng(-33.9046, 151.155)).draggable(true)); mMarkerB = getMap().addMarker(new MarkerOptions().position(new LatLng(-33.8291, 151.248)).draggable(true)); mPolyline = getMap().addPolyline(new PolylineOptions().geodesic(true)); Toast.makeText(this, "Drag the markers!", Toast.LENGTH_LONG).show(); showDistance(); }
@Override public void onMapReady(final GoogleMap map) { if (needsInit) { CameraUpdate center= CameraUpdateFactory.newLatLng(new LatLng(40.76793169992044, -73.98180484771729)); CameraUpdate zoom=CameraUpdateFactory.zoomTo(15); map.moveCamera(center); map.animateCamera(zoom); addMarker(map, 40.748963847316034, -73.96807193756104, R.string.un, R.string.united_nations); addMarker(map, 40.76866299974387, -73.98268461227417, R.string.lincoln_center, R.string.lincoln_center_snippet); addMarker(map, 40.765136435316755, -73.97989511489868, R.string.carnegie_hall, R.string.practice_x3); addMarker(map, 40.70686417491799, -74.01572942733765, R.string.downtown_club, R.string.heisman_trophy); } map.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater())); map.setOnInfoWindowClickListener(this); map.setOnMarkerDragListener(this); }
mMap.setOnMarkerDragListener(this); mMap.setOnMapLongClickListener(this);
@Override public void onMapReady(GoogleMap map) { map.setOnMarkerDragListener(SplitStreetViewPanoramaAndMapDemoActivity.this); // Creates a draggable marker. Long press to drag. mMarker = map.addMarker(new MarkerOptions() .position(markerPosition) .icon(BitmapDescriptorFactory.fromResource(R.drawable.pegman)) .draggable(true)); } });
@Override public void onMapReady(GoogleMap map) { MarkerOptions markerOptions = new MarkerOptions() .position(mMarkerPosition) .icon(BitmapDescriptorFactory.defaultMarker(mMarkerInfo.mHue)) .draggable(true); map.addMarker(markerOptions); map.setOnMarkerDragListener(this); map.setOnMarkerClickListener(this); if (mMoveCameraToMarker) { map.animateCamera(CameraUpdateFactory.newLatLng(mMarkerPosition)); } }
@Override public final void setOnMarkerDragListener(OnMarkerDragListener listener) { map.setOnMarkerDragListener(listener); }
@Override public void call() { googleMap.setOnMarkerDragListener(null); } }));
@Override public void onMapReady(GoogleMap map) { mMap = map; // Hide the zoom controls as the button panel will cover it. mMap.getUiSettings().setZoomControlsEnabled(false); // Add lots of markers to the map. addMarkersToMap(); // Setting an info window adapter allows us to change the both the contents and look of the // info window. mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter()); // Set listeners for marker events. See the bottom of this class for their behavior. mMap.setOnMarkerClickListener(this); mMap.setOnInfoWindowClickListener(this); mMap.setOnMarkerDragListener(this); mMap.setOnInfoWindowCloseListener(this); mMap.setOnInfoWindowLongClickListener(this); // Override the default content description on the view, for accessibility mode. // Ideally this string would be localised. mMap.setContentDescription("Map with lots of markers."); LatLngBounds bounds = new LatLngBounds.Builder() .include(PERTH) .include(SYDNEY) .include(ADELAIDE) .include(BRISBANE) .include(MELBOURNE) .include(DARWIN) .build(); mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50)); }
@Override public void call(final Subscriber<? super MarkerDragEvent> subscriber) { GoogleMap.OnMarkerDragListener listener = new GoogleMap.OnMarkerDragListener() { @Override public void onMarkerDragStart(Marker marker) { onEvent(MarkerDragEvent.create(marker, MarkerDragEvent.Kind.START)); } @Override public void onMarkerDrag(Marker marker) { onEvent(MarkerDragEvent.create(marker, MarkerDragEvent.Kind.DRAG)); } @Override public void onMarkerDragEnd(Marker marker) { onEvent(MarkerDragEvent.create(marker, MarkerDragEvent.Kind.END)); } private void onEvent(MarkerDragEvent event) { if (!subscriber.isUnsubscribed()) { subscriber.onNext(event); } } }; googleMap.setOnMarkerDragListener(listener); subscriber.add(Subscriptions.create(new Action0() { @Override public void call() { googleMap.setOnMarkerDragListener(null); } })); } }
private MarkerBuilderManagerV2(Builder b) { this.context = b.context; this.googleMap = b.googleMap; this.circleManagerListener = b.circleManagerListener; this.isEnabled = b.isEnabled; this.radius = b.radius; this.circleId = b.circleId; this.strokeWidth = b.strokeWidth; this.strokeColor = b.strokeColor; this.fillColor = b.fillColor; this.minRadius = b.minRadius; this.maxRadius = b.maxRadius; this.centerIcon = b.centerIcon; this.centerBitmap = b.centerBitmap; this.resizerIcon = b.resizerIcon; this.centerOffsetHorizontal = b.centerOffsetHorizontal; this.centerOffsetVertical = b.centerOffsetVertical; googleMap.setOnMarkerDragListener(this); googleMap.setOnMapLongClickListener(this); googleMap.setOnMapClickListener(this); googleMap.setOnMarkerClickListener(this); }
@Override public void onMapReady(GoogleMap map) { mMap = map; // Hide the zoom controls as the button panel will cover it. mMap.getUiSettings().setZoomControlsEnabled(true); if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MainActivity.this, new String[]{ Manifest.permission.ACCESS_FINE_LOCATION }, MY_PERMISSIONS_REQUEST_FINE_LOCATION); return; } mMap.setMyLocationEnabled(true); mMap.setOnMarkerDragListener(this); mMap.setOnMapClickListener(this); marker = mMap.addMarker(new MarkerOptions() .position(lastLocation) .draggable(true)); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(lastLocation,17)); }
@Test public void shouldEmmitEndDragEvent() throws Exception { TestSubscriber<DragEvent> testSubscriber = new TestSubscriber<>(); new MarkerDragFunc().call(googleMap) .subscribe(testSubscriber); verify(googleMap).setOnMarkerDragListener(argumentCaptor.capture()); argumentCaptor.getValue().onMarkerDragEnd(null); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); argumentCaptor.getValue().onMarkerDragEnd(null); testSubscriber.assertValueCount(2); }
@Test public void shouldEmmitDragEvent() throws Exception { TestSubscriber<DragEvent> testSubscriber = new TestSubscriber<>(); new MarkerDragFunc().call(googleMap) .subscribe(testSubscriber); verify(googleMap).setOnMarkerDragListener(argumentCaptor.capture()); argumentCaptor.getValue().onMarkerDrag(null); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); argumentCaptor.getValue().onMarkerDrag(null); testSubscriber.assertValueCount(2); }
@Test public void shouldEmmitStartDragEvent() throws Exception { TestSubscriber<DragEvent> testSubscriber = new TestSubscriber<>(); new MarkerDragFunc().call(googleMap) .subscribe(testSubscriber); verify(googleMap).setOnMarkerDragListener(argumentCaptor.capture()); argumentCaptor.getValue().onMarkerDragStart(null); testSubscriber.assertNoErrors(); testSubscriber.assertValueCount(1); argumentCaptor.getValue().onMarkerDragStart(null); testSubscriber.assertValueCount(2); }
mMap = ((SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map)).getMap(); mMap.setOnMarkerDragListener(this);
protected void addSingleMarkerToMap(LatLng latLng) { if (mMap != null) { if (mCurrentMapMarker != null) { mCurrentMapMarker.remove(); } CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng) .zoom(getDefaultZoom()) .build(); hasWiderZoom = false; mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); mCurrentMapMarker = addMarker(latLng); mMap.setOnMarkerDragListener(this); extractGeocode(latLng.latitude, latLng.longitude); } }
mMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() { @Override public void onMarkerDragStart(Marker marker) {
void addOriginMarker(LatLng latLng) { if (mMap != null) { if (mOriginMapMarker != null) { mOriginMapMarker.remove(); mOriginMapMarker = null; } CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng) .zoom(getDefaultZoom()) .build(); hasWiderZoom = false; mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); if (mOriginMarkerPinIconRes != DEFAULT_MARKER_ICON_RES) { mOriginMapMarker = addMarker(latLng, mOriginMarkerPinIconRes); } else { mOriginMapMarker = addMarker(latLng); } mMap.setOnMarkerDragListener(this); showBothMarkersAndGetDirections(); } }
googleMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() { @Override public void onMarkerDragStart(Marker marker) {