public void run() { if (mCurrentFocusVehicleMarker != null && mCurrentFocusVehicleMarker.isInfoWindowShown()) { // Force an update of the marker balloon, so "last updated" time ticks up mCurrentFocusVehicleMarker.showInfoWindow(); } }
// --------------------------------------------------------------------------------------------- // Method for updating the icons of the markers and plotting the new route. -------------------- private void updateMarkersAndRoute(Marker marker) { Log.d("VetFirstActivity", ">> Marker clicked: " + marker.getTitle()); vetMap.clear(); int temp_i = 0; for (int i = 0; i < markerOptionsList.size(); i++) { if (marker.getTitle().equals(markerOptionsList.get(i).getTitle())) { temp_i = i; Log.d("VetFirstActivity", ">> Position in list:" + temp_i); } } for (int i = 0; i < markerOptionsList.size(); i++) { if ((i != nearestVetPosition) && (i != temp_i)) { vetMap.addMarker(markerOptionsList.get(i).icon(vetIcon).alpha(0.6f)); } else if ((i != nearestVetPosition) && (i == temp_i)) { vetMap.addMarker(markerOptionsList.get(i).icon(vetIcon).alpha(1f)); } else { vetMap.addMarker(markerOptionsList.get(i).icon(nearestVetIcon)); } } vetMap.addMarker( new MarkerOptions() .position(currentLocationLatLng) .title("Βρίσκεστε εδώ") .icon(currentLocationIcon)); GetRouteTask markerGetRouteTask = new GetRouteTask(); markerGetRouteTask.execute( ConnectionManager.getDirectionsURL(currentLocationLatLng, vetLatLng)); vetMap.animateCamera(CameraUpdateFactory.newLatLng(vetLatLng)); }
public void animateMarker(final Marker marker, final Location location) { final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); final LatLng startLatLng = marker.getPosition(); final double startRotation = marker.getRotation(); final long duration = 500; final Interpolator interpolator = new LinearInterpolator(); handler.post( new Runnable() { @Override public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * location.getLongitude() + (1 - t) * startLatLng.longitude; double lat = t * location.getLatitude() + (1 - t) * startLatLng.latitude; float rotation = (float) (t * location.getBearing() + (1 - t) * startRotation); marker.setPosition(new LatLng(lat, lng)); marker.setRotation(rotation); if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16); } } }); }
private Boolean updateMarkers(ReadableArray markerArray) { try { // First clear all markers from the map for (Marker marker : mapMarkers) { marker.remove(); } mapMarkers.clear(); markerLookup.clear(); // All markers to map for (int i = 0; i < markerArray.size(); i++) { ReadableMap markerJson = markerArray.getMap(i); if (markerJson.hasKey("coordinates")) { Marker marker = map.addMarker(createMarker(markerJson)); if (markerJson.hasKey("id")) { // As we have to lookup it either way, switch it around markerLookup.put(marker.getId(), markerJson.getString("id")); markerLookup.put(markerJson.getString("id"), marker.getId().replace("m", "")); } mapMarkers.add(marker); } else break; } return true; } catch (Exception e) { e.printStackTrace(); return false; } }
private void addMarkedMarkers() { // add marked markers // add markets markedList = MarkedContent.ITEMS_DISTINCT(); for (MarkedItem item : markedList) { // is the marked add more than once int numberOfMarkets = MarkedContent.numberOfMarkets(item.name); BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.da_marker_red); if (numberOfMarkets <= 1) { icon = BitmapDescriptorFactory.fromResource(R.drawable.da_marker_yellow); } MarkerOptions markerOption = new MarkerOptions() .position(new LatLng(item.latitude, item.longitude)) .title(item.name) .snippet("klik for at se detaljer") .anchor(0.5f, 0.5f) .icon(icon); Marker marker = googleMap.addMarker(markerOption); item.markerId = marker.getId(); } }
@Override public void onProgressChanged(SeekBar seekBar, int value, boolean byUser) { Location you = new Location("you"); tvDist.setText("RADIUS: " + ((double) value) / 10 + "km"); if (seekBar == sbRadOuter && byUser) { you.setLatitude(myLatLng.latitude); you.setLongitude(myLatLng.longitude); if (value != 0) { Polyline temp = drawCircle(myLatLng, ((double) value) / 10, Color.BLUE, 5); outerCircle.remove(); outerCircle = temp; for (Marker marker : markersOnMap) { markerLatLng = marker.getPosition(); markerLocation.setLatitude(markerLatLng.latitude); markerLocation.setLongitude(markerLatLng.longitude); if (you.distanceTo(markerLocation) > value * 100) { marker.setVisible(false); } else { marker.setVisible(true); } } } } }
public static Marker placeRobotMarkerOnMap( Marker marker, GoogleMap mMap, LatLng location, boolean animateTheCamera, Resources res, Context context) { try { marker.remove(); } catch (Exception e) { e.printStackTrace(); Log.e("MapUtilities", "placeMarkerOnMapUserLatLng: Could not remove Robots Marker"); } MarkerOptions m = new MarkerOptions() .position(location) .icon(BitmapDescriptorFactory.fromResource(R.drawable.robot)) .title("ROBOT"); marker = mMap.addMarker(m); marker.showInfoWindow(); if (animateTheCamera) animateCameraLatLng(mMap, location, res); Log.d("ROBOT_LOCATION", "Latitude: " + location.latitude + " Longitude: " + location.longitude); // Toast.makeText(context,"Latitude: " +location.latitude+" Longitude: // "+location.longitude,Toast.LENGTH_LONG).show(); return marker; }
private void setMarkersOptions(Location loc) { boolean visible = true; if (markersOnMap == null) { markersOnMap = new ArrayList<Marker>(); } for (Task task : TaskList.getInstance(getApplicationContext()).getTasks()) { LatLng temp = getLatLngIfPossible(task.getLocation()); if (temp != null) { Location tloc = new Location(task.getLocation()); tloc.setLatitude(temp.latitude); tloc.setLongitude(temp.longitude); float dist = tloc.distanceTo(loc); Marker tempMarker = map.addMarker( new MarkerOptions() .position(temp) .visible(visible) .title(String.valueOf(task.getTask_id())) .icon(BitmapDescriptorFactory.fromResource(R.drawable.marke_65px))); if (dist > sbRadOuter.getProgress() * 100) { tempMarker.setVisible(false); } markersOnMap.add(tempMarker); } } }
@Override public View getInfoWindow(Marker marker) { long task_id; try { task_id = Long.parseLong(marker.getTitle()); } catch (Exception e) { task_id = -1; } if (task_id != -1) { LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View windowview = inflater.inflate(R.layout.task_window, null); Task task = TaskList.getInstance(getApplicationContext()) .getTaskById(Long.parseLong(marker.getTitle())); ((TextView) windowview.findViewById(R.id.tvTitleWin)).setText(task.getTitle()); ((TextView) windowview.findViewById(R.id.tvDescriptionWin)).setText(task.getDesc()); ((TextView) windowview.findViewById(R.id.tvLocationWin)).setText(task.getLocation()); ((TextView) windowview.findViewById(R.id.tvFromToWin)).setText(task.getFromTo()); String status = (task.isChecked() == 1) ? "Done" : "Not Done"; ((TextView) windowview.findViewById(R.id.tvStatusWin)).setText(status); return windowview; } else { return null; } }
/* * Map methods */ public static void staticOnMarkerClick( SherlockFragmentActivity mActivity, GoogleMap map, Marker marker, OnDetailsClick onDetailsClickImplementation) { String id = marker.getTitle(); List<LocatedObject> list = MapManager.ClusteringHelper.getFromGridId(id); if (list == null || list.isEmpty()) { return; } if (list.size() > 1 && map.getCameraPosition().zoom == map.getMaxZoomLevel()) { AlertRoadsInfoDialog infoDialog = new AlertRoadsInfoDialog(onDetailsClickImplementation); Bundle args = new Bundle(); args.putSerializable(AlertRoadsInfoDialog.ARG_ALERTSLIST, (ArrayList) list); infoDialog.setArguments(args); infoDialog.show(mActivity.getSupportFragmentManager(), "dialog"); } else if (list.size() > 1) { map.animateCamera( CameraUpdateFactory.newLatLngZoom( marker.getPosition(), map.getCameraPosition().zoom + 1)); MapManager.fitMapWithOverlays(list, map); } else { AlertRoadLoc alert = (AlertRoadLoc) list.get(0); AlertRoadsInfoDialog infoDialog = new AlertRoadsInfoDialog(onDetailsClickImplementation); Bundle args = new Bundle(); args.putSerializable(AlertRoadsInfoDialog.ARG_ALERT, alert); infoDialog.setArguments(args); infoDialog.show(mActivity.getSupportFragmentManager(), "dialog"); } }
@Override public void onMapClick(LatLng point) { // mTapTextView.setText("tapped, point=" + point); int max = markers.size(); // clear all markers for (int j = 0; j < max; j++) { marker = markers.get(j); marker.setVisible(false); } for (int i = 0; i < max; i++) { polygon = polygons.get(i); polygonPath = polygon.getPoints(); if (PolyUtil.containsLocation(point, polygonPath, false)) { // when click change polygon color polygon.setFillColor(randomColor()); marker = markers.get(i); marker.setVisible(true); marker.showInfoWindow(); break; } // if } // for }
/* Executed after the complete execution of doInBackground() method */ @Override protected void onPostExecute(Place[] places) { mPlaces = places; if (places == null) return; for (int i = 0; i < places.length; i++) { Place place = places[i]; /* Getting latitude of the place */ double lat = Double.parseDouble(place.mLat); /* Getting longitude of the place */ double lng = Double.parseDouble(place.mLng); LatLng latLng = new LatLng(lat, lng); if (i == 0 && isTextSearch) mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15)); Marker m = drawMarker(latLng, Constant.UNDEFINED_COLOR); /* Adding place reference to HashMap with marker id as HashMap key to get its reference in infowindow click event listener */ mHMReference.put(m.getId(), place); } }
@Override public View getInfoWindow(Marker marker) { // Don't show an InfoWindow for proppellern. if (marker.getPosition().equals(PROPELLERN) && null == marker.getTitle()) { return null; } ImageView pic = (ImageView) mWindow.findViewById(R.id.badge); pic.setImageResource(R.drawable.nopo); String title = marker.getTitle(); TextView titleUi = (TextView) mWindow.findViewById(R.id.title); titleUi.setText(title); titleUi.setTextColor(getResources().getColor(R.color.red)); String snippet = marker.getSnippet(); TextView snippetUi = (TextView) mWindow.findViewById(R.id.snippet); snippetUi.setText(snippet); TextView numBeers = (TextView) mWindow.findViewById(R.id.numBeers); String beerText = ""; int beers = beerMap.get(marker); if (0 < beers) { beerText = beerMap.get(marker) + " " + (beers == 1 ? "beer" : "beers") + " reported."; } numBeers.setText(beerText); return mWindow; }
/** Displays current location with information about timezone etc. */ private void displayCurrentLocation() { final double[] loc = getLocation(); if (loc == null) { Toast.makeText(this, "Could not fetch location", Toast.LENGTH_LONG).show(); return; } final View infoWindow = LayoutInflater.from(this).inflate(R.layout.infowindow, null); mMap.setInfoWindowAdapter( new GoogleMap.InfoWindowAdapter() { @Override public View getInfoWindow(Marker marker) { return null; } @Override public View getInfoContents(Marker marker) { populateInfoWindow(loc, infoWindow); return infoWindow; } }); Marker me = mMap.addMarker( new MarkerOptions() .position(new LatLng(loc[0], loc[1])) .title("Current Location") .icon(BitmapDescriptorFactory.fromResource(android.R.drawable.star_on))); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(loc[0], loc[1]), 5)); me.showInfoWindow(); }
@Override public void onMapClick(LatLng point) { /** We prevents to pu more than the max nb of markers */ if (markers.size() < nbPoints) { Marker marker = map.addMarker( new MarkerOptions().position(point).title("Adresse postale").draggable(true)); markers.add(marker); MarkerPos markerpos = new MarkerPos(marker, point); getAddress(markerpos); if (markers.size() >= 2) { // Instantiates a new Polygon object and adds points to define a rectangle rectOptions = new PolygonOptions(); for (Marker mark : markers) { rectOptions = rectOptions.add(mark.getPosition()); } // Remove the Polygon if exists if (polygon != null) { polygon.remove(); } // Get back the mutable Polygon polygon = map.addPolygon(rectOptions); } } else { Toast.makeText( getApplicationContext(), "Nombre de points maximum atteint", Toast.LENGTH_SHORT) .show(); } }
// Fires when a long press happens on the map @Override public void onMapLongClick(final LatLng point) { // Toast.makeText(this, "Long Press", Toast.LENGTH_LONG).show(); if (pinDisplayed) { map.clear(); pinDisplayed = false; } // Define color of marker icon BitmapDescriptor defaultMarker = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED); // Creates and adds marker to the map Marker marker = map.addMarker( new MarkerOptions() .position(point) .title(getResources().getString(R.string.deliver_here)) .icon(defaultMarker)); latitude = marker.getPosition().latitude; longitude = marker.getPosition().longitude; deliveryLocation = getAddress(latitude, longitude); pinDisplayed = true; dropPinEffect(marker); }
public Waypoint getWaypoint(Marker m) { if (waypoints.containsKey(m.getId())) { return waypoints.get(m.getId()); } else { return null; } }
@Override public void onInfoWindowClick(Marker marker) { if (marker.getTitle().equals(getString(R.string.Marker_NotRegistered))) { // 未登録のマーカーであれば情報を追加する // 地点情報追加画面に遷移 Intent intent = new Intent(this, AddPlaceActivity.class); intent.putExtra("latitude", marker.getPosition().latitude); intent.putExtra("longitude", marker.getPosition().longitude); startActivityForResult(intent, 123); } PlaceInfo pInfo = new PlaceInfo(); pInfo.mMarker = marker; if (mPlaceInfoList.contains(pInfo)) { // マーカーの詳細情報画面を開く Intent intent = new Intent(this, DisplayDetailActivity.class); PlaceInfo pClone = mPlaceInfoList.get(mPlaceInfoList.indexOf(pInfo)).getSeralizable(); intent.putExtra("placeInfo", pClone); try { startActivity(intent); } catch (RuntimeException e) { Toast t = Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG); t.show(); e.getStackTrace(); } } }
@Override public void updateLocationMarker(Location location) { if (locationChangedListener != null) { currentUserLocation = location; locationChangedListener.onLocationChanged(location); } // Update clickable area LatLng userPosition = getUserLocation(location); if (userPositionClickArea == null) { MarkerOptions markerOptions = new MarkerOptions(); markerOptions.position(userPosition); markerOptions.anchor(0.4f, 0.4f); // strange google maps bug markerOptions.icon(BitmapDescriptorFactory.fromBitmap(clickableBitmap)); userPositionClickArea = googleMap.addMarker(markerOptions); } else { userPositionClickArea.setPosition(userPosition); } if (userPositionClickArea2 == null) { MarkerOptions markerOptions = new MarkerOptions(); markerOptions.position(userPosition); markerOptions.anchor(0.6f, 0.6f); // strange google maps bug markerOptions.icon(BitmapDescriptorFactory.fromBitmap(clickableBitmap)); userPositionClickArea2 = googleMap.addMarker(markerOptions); } else { userPositionClickArea2.setPosition(userPosition); } }
private void removeMarkers() { Log.d(TAG, "removeMarkers"); for (Marker m : markerMap.values()) { m.remove(); } markerMap.clear(); }
// Executed after the complete execution of doInBackground() method @Override protected void onPostExecute(List<HashMap<String, String>> list) { // Clears all the existing markers mGoogleMap.clear(); for (int i = 0; i < list.size(); i++) { // Creating a marker MarkerOptions markerOptions = new MarkerOptions(); // Getting a place from the places list HashMap<String, String> hmPlace = list.get(i); // Getting latitude of the place double lat = Double.parseDouble(hmPlace.get("lat")); // Getting longitude of the place double lng = Double.parseDouble(hmPlace.get("lng")); // Getting name String name = hmPlace.get("place_name"); // Getting vicinity String vicinity = hmPlace.get("vicinity"); // Getting the type String type = hmPlace.get("type"); // Getting the price_level String price = hmPlace.get("price"); int price_level = Integer.parseInt(price); int user_price = Integer.parseInt(price); LatLng latLng = new LatLng(lat, lng); // Setting the position for the marker markerOptions.position(latLng); // Setting the title for the marker. // This will be displayed on taping the marker markerOptions.title(name + " : " + vicinity); if (price_level <= user_price) { // Placing a marker on the touched position if (theRandomPlace != null && !theRandomPlace.equals(name)) { markerOptions.icon( BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)); } Marker marker = mGoogleMap.addMarker(markerOptions); String id = marker.getId(); placeArray.add(name); addressArray.add(vicinity); locationArray.add(latLng); idArray.add(id); } } done_loading = true; }
public void onUserSelectValue(String s) { for (Marker m : filePaths.keySet()) { if (filePaths.get(m).equals(s)) { currentLat = m.getPosition().latitude; currentLng = m.getPosition().longitude; break; } } startEditActivity(s); }
public Marker addMarkerToMap(Tag tag) { LatLng tempPos = new LatLng(tag.getLat(), tag.getLong()); MarkerOptions tempMarkerOptions = new MarkerOptions().position(tempPos).title(tag.getNAME()).snippet(tag.getDESCRIPTION()); Marker marker = MAP.addMarker(tempMarkerOptions); marker.setIcon(tag.getIcon()); marker.setDraggable(true); return marker; }
public void addMarker(ReadableMap config) { MarkerOptions options = createMarker(config); Marker marker = map.addMarker(options); mapMarkers.add(marker); if (config.hasKey("id")) { // As we have to lookup it either way, switch it around markerLookup.put(marker.getId(), config.getString("id")); markerLookup.put(config.getString("id"), marker.getId().replace("m", "")); } }
private void addMarker(GoogleMap map, double lat, double lon, int title, int snippet) { Marker marker = map.addMarker( new MarkerOptions() .position(new LatLng(lat, lon)) .title(getString(title)) .snippet(getString(snippet))); builder.include(marker.getPosition()); }
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (!checkReady()) { return; } float rotation = seekBar.getProgress(); for (Marker marker : mMarkerRainbow) { marker.setRotation(rotation); } }
public void updateFriendMarker(UserObject u) { if (!friend1.isVisible()) { friend1.setVisible(true); } friend1.setSnippet(u.getUsername()); friend1.setPosition(new LatLng(u.getLast_lat_double(), u.getLast_long_double())); Log.i( TAG, " updating friend location..... " + u.getLast_lat_double() + " " + u.getLast_long_double()); }
public static void fixZoomForMarkers(GoogleMap googleMap, List<Marker> markers) { if (markers != null && markers.size() > 0) { LatLngBounds.Builder bc = new LatLngBounds.Builder(); for (Marker marker : markers) { bc.include(marker.getPosition()); } googleMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), 50), 4000, null); } }
@Override public void onInfoWindowClick(Marker marker) { String windowTitle = marker.getTitle(); String windowSubtitle = marker.getSnippet(); Intent openBuildingInfo = new Intent(MapHandler.this, InformationManager.class); Bundle windowInformation = new Bundle(); windowInformation.putString("windowTitle", windowTitle); windowInformation.putString("windowSubtitle", windowSubtitle); openBuildingInfo.putExtras(windowInformation); startActivity(openBuildingInfo); }
private void showMarkerInfo(Marker marker) { marker.showInfoWindow(); if (mGoogleMap.getCameraPosition().zoom < DEFAULT_ZOOM) { mGoogleMap.animateCamera( CameraUpdateFactory.newLatLngZoom(marker.getPosition(), DEFAULT_ZOOM)); } else { mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition())); } }