Java Code Examples for com.google.android.gms.maps.model.Marker#showInfoWindow()

The following examples show how to use com.google.android.gms.maps.model.Marker#showInfoWindow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapViewPager.java    From MapViewPager with Apache License 2.0 6 votes vote down vote up
private GoogleMap.OnMarkerClickListener createMarkerClickListenerSingle(final Adapter adapter) {
    return new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            for (int i = 0; i < adapter.getCount(); i++) {
                CameraPosition cp = adapter.getCameraPosition(i);
                if (cp != null && cp.target != null
                        && cp.target.latitude == marker.getPosition().latitude
                        && cp.target.longitude == marker.getPosition().longitude) {
                    viewPager.setCurrentItem(i);
                    marker.showInfoWindow();
                    return true;
                }
            }
            return false;
        }
    };
}
 
Example 2
Source File: PTRMapFragment.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
public void addMarker( float color, LatLng latLng, String title ) {
	if( mMap == null )
		mMap = ( (SupportMapFragment) getFragmentManager()
				.findFragmentById( R.id.map ) )
				.getMap();

	if( latLng == null || mMap == null )
		return;

	MarkerOptions markerOptions = new MarkerOptions().position( latLng );
	if( !title.isEmpty() )
		markerOptions.title( title );

	if( color == 0 )
		color = BitmapDescriptorFactory.HUE_RED;

	markerOptions.icon( BitmapDescriptorFactory.defaultMarker( color ) );
	Marker marker = mMap.addMarker( markerOptions );
	if( !markerLocations.contains( marker ) )
		markerLocations.add( marker );

	marker.showInfoWindow();
}
 
Example 3
Source File: MyHistoricalLocationMarkerCollection.java    From mage-android with Apache License 2.0 6 votes vote down vote up
@Override
public void refreshMarkerIcons(Filter<Temporal> filter) {
	for (Marker m : locationIdToMarker.values()) {
		Pair<Location, User> pair = markerIdToLocation.get(m.getId());
		Location location = pair.first;

		if (location != null) {
			boolean showWindow = m.isInfoWindowShown();
			// make sure to set the Anchor after this call as well, because the size of the icon might have changed
			m.setIcon(LocationBitmapFactory.dotBitmapDescriptor(context, location));
			m.setAnchor(0.5f, 1.0f);
			if (showWindow) {
				m.showInfoWindow();
			}
		}
	}
}
 
Example 4
Source File: LocationPickerActivity.java    From LocationPicker with MIT License 6 votes vote down vote up
private void addMarker() {

        LatLng coordinate = new LatLng(mLatitude, mLongitude);
        if (mMap != null) {
            MarkerOptions markerOptions;
            try {
                mMap.clear();
                imgSearch.setText("" + userAddress);

                markerOptions = new MarkerOptions().position(coordinate).title(userAddress).icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_place_red_800_24dp));
                CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(coordinate, 14);
                mMap.animateCamera(cameraUpdate);
                mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

                Marker marker = mMap.addMarker(markerOptions);
                marker.showInfoWindow();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

    }
 
Example 5
Source File: ObservationMarkerCollection.java    From mage-android with Apache License 2.0 6 votes vote down vote up
@Override
 public void refreshMarkerIcons(Filter<Temporal> filter) {
     for (MapMarkerObservation mapMarkerObservation : mapObservations.getMarkers()) {
         Marker marker = mapMarkerObservation.getMarker();
         Observation observation = mapMarkerObservation.getObservation();
if (observation != null) {
             if (filter != null && !filter.passesFilter(observation)) {
                 this.remove(observation);
             } else {
                 boolean showWindow = marker.isInfoWindowShown();
                 // make sure to set the Anchor after this call as well, because the size of the icon might have changed
                 marker.setIcon(ObservationBitmapFactory.bitmapDescriptor(context, observation));
                 marker.setAnchor(0.5f, 1.0f);
                 if (showWindow) {
                     marker.showInfoWindow();
                 }
             }
         }
     }
 }
 
Example 6
Source File: ObservationMarkerCollection.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapClick(LatLng latLng) {

    MapShapeObservation mapShapeObservation = mapObservations.getClickedShape(map, latLng);
    if (mapShapeObservation != null) {
        Marker shapeMarker = mapObservationManager.addShapeMarker(latLng, visible);
        mapObservations.setShapeMarker(shapeMarker, mapShapeObservation);
        map.setInfoWindowAdapter(infoWindowAdapter);
        shapeMarker.showInfoWindow();
    }
}
 
Example 7
Source File: Clusterkraf.java    From clusterkraf with Apache License 2.0 5 votes vote down vote up
/**
 * Show the InfoWindow for the passed Marker and ClusterPoint
 * 
 * @param marker
 * @param clusterPoint
 */
public void showInfoWindow(Marker marker, ClusterPoint clusterPoint) {
	GoogleMap map = mapRef.get();
	if (map != null && marker != null && clusterPoint != null) {
		long dirtyUntil = System.currentTimeMillis() + options.getShowInfoWindowAnimationDuration();
		innerCallbackListener.clusteringOnCameraChangeListener.setDirty(dirtyUntil);
		CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLng(marker.getPosition());
		map.animateCamera(cameraUpdate, options.getShowInfoWindowAnimationDuration(), new CancelableCallback() {

			@Override
			public void onFinish() {
				innerCallbackListener.handler.post(new Runnable() {

					@Override
					public void run() {
						innerCallbackListener.clusteringOnCameraChangeListener.setDirty(0);

					}
				});
			}

			@Override
			public void onCancel() {
				innerCallbackListener.clusteringOnCameraChangeListener.setDirty(0);
			}
		});
		marker.showInfoWindow();
	}
}
 
Example 8
Source File: DefaultClusterRenderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a cached marker for a ClusterItem already exists on the map so the marker may
 * be updated to the latest item values. Default implementation updates the title and snippet
 * of the marker if they have changed and refreshes the info window of the marker if it is open.
 * Note that the contents of the item may not have changed since the cached marker was created -
 * implementations of this method are responsible for checking if something changed (if that
 * matters to the implementation).
 *
 * The first time {@link ClusterManager#cluster()} is invoked on a set of items
 * {@link #onBeforeClusterItemRendered(ClusterItem, MarkerOptions)} will be called and
 * {@link #onClusterItemUpdated(ClusterItem, Marker)} will not be called.
 * If an item is removed and re-added (or updated) and {@link ClusterManager#cluster()} is
 * invoked again, then {@link #onClusterItemUpdated(ClusterItem, Marker)} will be called and
 * {@link #onBeforeClusterItemRendered(ClusterItem, MarkerOptions)} will not be called.
 *
 * @param item item being updated
 * @param marker cached marker that contains a potentially previous state of the item.
 */
protected void onClusterItemUpdated(@NonNull T item, @NonNull Marker marker) {
    boolean changed = false;
    // Update marker text if the item text changed - same logic as adding marker in CreateMarkerTask.perform()
    if (item.getTitle() != null && item.getSnippet() != null) {
        if (!item.getTitle().equals(marker.getTitle())) {
            marker.setTitle(item.getTitle());
            changed = true;
        }
        if (!item.getSnippet().equals(marker.getSnippet())) {
            marker.setSnippet(item.getSnippet());
            changed = true;
        }
    } else if (item.getSnippet() != null && !item.getSnippet().equals(marker.getTitle())) {
        marker.setTitle(item.getSnippet());
        changed = true;
    } else if (item.getTitle() != null && !item.getTitle().equals(marker.getTitle())) {
        marker.setTitle(item.getTitle());
        changed = true;
    }
    // Update marker position if the item changed position
    if (!marker.getPosition().equals(item.getPosition())) {
        marker.setPosition(item.getPosition());
        changed = true;
    }
    if (changed && marker.isInfoWindowShown()) {
        // Force a refresh of marker info window contents
        marker.showInfoWindow();
    }
}
 
Example 9
Source File: CampusMapActivity.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the buildings specified in buildingIdList or shows the user an
 * error if any of the buildingIds are invalid
 *
 * @param autoZoom - true to autozoom to 16 when moving (will not animate!)
 *                 to the building, false to just animate to building; should
 *                 only be true when you are entering the map from an entry point
 *                 other than the dashboard
 */
public void loadBuildingOverlay(boolean centerCameraOnBuildings, boolean autoZoom) {
    // TODO: don't center on buildings when restoring state
    int foundCount = 0;
    llbuilder = LatLngBounds.builder();

    for (Placemark pm : buildingDataSet) {
        if (buildingIdList.contains(pm.getTitle())) {
            foundCount++;

            LatLng buildingLatLng = new LatLng(pm.getLatitude(), pm.getLongitude());
            Marker buildingMarker = shownBuildings.addMarker(new MarkerOptions()
                        .position(buildingLatLng)
                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_building2))
                        .title(pm.getTitle())
                        .snippet(pm.getDescription()));
            llbuilder.include(buildingLatLng);

            // don't move the camera around or show InfoWindows for more than one building
            if (buildingIdList.size() == 1 && centerCameraOnBuildings) {
                if (autoZoom) {
                    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(buildingLatLng, 16f));
                } else {
                    mMap.animateCamera(CameraUpdateFactory.newLatLng(buildingLatLng));
                }
                setInitialLocation = true;
                buildingMarker.showInfoWindow();
            }
        }
    }
    if (foundCount > 1 && centerCameraOnBuildings) {
        mSetCameraToBounds = true;
    }
    if (foundCount != buildingIdList.size()) {
        Toast.makeText(this, "One or more buildings could not be found", Toast.LENGTH_SHORT)
                .show();
    }
    buildingIdList.clear();
}
 
Example 10
Source File: MyHistoricalLocationMarkerCollection.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
	Pair<Location, User> pair = markerIdToLocation.get(marker.getId());

	if (pair == null) {
		return false;
	}

	marker.showInfoWindow();

	return true;
}
 
Example 11
Source File: ObservationMarkerCollection.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {

    boolean handled = false;

    Observation observation = mapObservations.getMarkerObservation(marker.getId());
    if (observation != null) {
        final Geometry g = observation.getGeometry();
        if (g != null) {
            Point point = GeometryUtils.getCentroid(g);
            LatLng latLng = new LatLng(point.getY(), point.getX());
            Float accuracy = observation.getAccuracy();
            if (accuracy != null) {
                try {
                    if (observationAccuracyCircle != null) {
                        observationAccuracyCircle.second.remove();
                    }

                    Circle circle = map.addCircle(new CircleOptions()
                        .center(latLng)
                        .radius(accuracy)
                        .fillColor(context.getResources().getColor(R.color.accuracy_circle_fill))
                        .strokeColor(context.getResources().getColor(R.color.accuracy_circle_stroke))
                        .strokeWidth(2.0f));

                    observationAccuracyCircle = new Pair<>(observation.getRemoteId(), circle);
                } catch (NumberFormatException nfe) {
                    Log.e(LOG_NAME, "Problem adding accuracy circle to the map.", nfe);
                }
            }
        }

        map.setInfoWindowAdapter(infoWindowAdapter);
        marker.showInfoWindow();
        handled = true;
    }

    return handled;
}
 
Example 12
Source File: LocationMarkerCollection.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void refreshMarkerIcons(Filter<Temporal> filter) {
	Collection<Marker> markers = new ArrayList<>(userIdToMarker.values());
	for (Marker m : markers) {
		Pair<Location, User> pair = markerIdToPair.get(m.getId());
		Location location = pair.first;
		User user = pair.second;
		if (location != null) {
			if (filter != null && !filter.passesFilter(location)) {
				remove(pair);
			} else {
				boolean showWindow = m.isInfoWindowShown();
				try {
					// make sure to set the Anchor after this call as well, because the size of the icon might have changed
					m.setIcon(LocationBitmapFactory.bitmapDescriptor(context, location, user));
					m.setAnchor(0.5f, 1.0f);
				} catch (Exception ue) {
					Log.e(LOG_NAME, "Error refreshing the icon for user: " + user.getId(), ue);
				}

				if (showWindow) {
					m.showInfoWindow();
				}
			}
		}
	}
}
 
Example 13
Source File: MapViewPager.java    From MapViewPager with Apache License 2.0 5 votes vote down vote up
private GoogleMap.OnMarkerClickListener createMarkerClickListenerMulti(final MultiAdapter adapter) {
    return new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            for (int page = 0; page < adapter.getCount(); page++) {
                if (adapter.getCameraPositions(page) != null) {
                    for (int i = 0; i < adapter.getCameraPositions(page).size(); i++) {
                        CameraPosition cp = adapter.getCameraPositions(page).get(i);
                        if (cp != null && cp.target != null
                                && cp.target.latitude == marker.getPosition().latitude
                                && cp.target.longitude == marker.getPosition().longitude) {
                            if (marker.isInfoWindowShown()) { // this doesn't seem to work !!
                                viewPager.setCurrentItem(page);
                                return true;
                            }
                            else {
                                viewPager.setCurrentItem(page);
                                map.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
                                marker.showInfoWindow();
                                return true;
                            }
                        }
                    }
                }
            }
            return false;
        }
    };
}
 
Example 14
Source File: PlaceMapFragment.java    From RxGpsService with Apache License 2.0 5 votes vote down vote up
private void showMarkInfoWindow(int objectId) {
    if (objectId > 0) {
        for (Map.Entry<Marker, Object> entry : markersMap.entrySet()) {
            Object object = entry.getValue();

            if (object instanceof Place) {
                Marker marker = entry.getKey();
                Place place = (Place) object;
                if (place.getId() == objectId) marker.showInfoWindow();
            }
        }
    }
}
 
Example 15
Source File: LocationMarkerCollection.java    From mage-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
	Pair<Location, User> pair = markerIdToPair.get(marker.getId());
	if (pair == null) {
		return false;
	}

	Location location = pair.first;
	User user = pair.second;

	final Geometry g = location.getGeometry();
	if (g != null) {
		Point point = GeometryUtils.getCentroid(g);
		LatLng latLng = new LatLng(point.getY(), point.getX());
		LocationProperty accuracyProperty = location.getPropertiesMap().get("accuracy");
		if (accuracyProperty != null && !accuracyProperty.getValue().toString().trim().isEmpty()) {
			try {
				float accuracy = Float.parseFloat(accuracyProperty.getValue().toString());
				if (clickedAccuracyCircle != null) {
					clickedAccuracyCircle.remove();
				}

				int color = LocationBitmapFactory.locationColor(context, location);
				clickedAccuracyCircle = map.addCircle(new CircleOptions()
						.center(latLng)
						.radius(accuracy)
						.fillColor(ColorUtils.setAlphaComponent(color, (int) (256 * .20)))
						.strokeColor(ColorUtils.setAlphaComponent(color, (int) (256 * .87)))
						.strokeWidth(2.0f));
				clickedAccuracyCircleUserId = user.getId();
			} catch (NumberFormatException nfe) {
				Log.e(LOG_NAME, "Problem adding accuracy circle to the map.", nfe);
			}
		}
	}

	map.setInfoWindowAdapter(infoWindowAdapter);
	// make sure to set the Anchor after this call as well, because the size of the icon might have changed
	marker.setIcon(LocationBitmapFactory.bitmapDescriptor(context, location, user));
	marker.setAnchor(0.5f, 1.0f);
	marker.showInfoWindow();
	return true;
}
 
Example 16
Source File: MapFragment.java    From Android-GoogleMaps-Part1 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
    marker.showInfoWindow();
    return true;
}
 
Example 17
Source File: MapFragment.java    From AndroidDemoProjects with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
    marker.showInfoWindow();
    return true;
}
 
Example 18
Source File: MapFragment.java    From mage-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
	hideKeyboard();

	observations.offMarkerClick();

	// search marker
	if(searchMarkers != null) {
		for(Marker m :searchMarkers) {
			 if(marker.getId().equals(m.getId())) {
					m.showInfoWindow();
					return true;
			 }
		}
	}

	// You can only have one marker click listener per map.
	// Lets listen here and shell out the click event to all
	// my marker collections. Each one need to handle
	// gracefully if it does not actually contain the marker
	if (observations.onMarkerClick(marker)) {
		return true;
	}

	if (locations.onMarkerClick(marker)) {
		return true;
	}

	if (historicLocations.onMarkerClick(marker)) {
		return true;
	}

	// static layer
	if(marker.getSnippet() != null) {
		View markerInfoWindow = LayoutInflater.from(getActivity()).inflate(R.layout.static_feature_infowindow, null, false);
		WebView webView = markerInfoWindow.findViewById(R.id.static_feature_infowindow_content);
		webView.loadData(marker.getSnippet(), "text/html; charset=UTF-8", null);
		new AlertDialog.Builder(getActivity())
			.setView(markerInfoWindow)
			.setPositiveButton(android.R.string.yes, null)
			.show();
	}
	return true;
}
 
Example 19
Source File: MainActivity.java    From effective_android_sample with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
    marker.showInfoWindow(); // ピンの上にバルーンを表示
    return false;
}
 
Example 20
Source File: MapActivity.java    From homeassist with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onMarkerClick(Marker marker) {
    Log.d("YouQi", "hello");
    marker.showInfoWindow();
    return true;
}