Java Code Examples for com.google.android.gms.maps.GoogleMap#addMarker()

The following examples show how to use com.google.android.gms.maps.GoogleMap#addMarker() . 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: CacheDetailActivity.java    From Forage with Mozilla Public License 2.0 8 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    googleMap.getUiSettings().setMapToolbarEnabled(false);

    // Add marker for geocache and move camera
    LatLng markerPos = new LatLng(location.getLatitude(), location.getLongitude());
    googleMap.addMarker(new MarkerOptions()
            .position(markerPos));

    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(markerPos)
            .zoom(13).build();

    googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

}
 
Example 2
Source File: GoogleMapActivity.java    From coursera-android with MIT License 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap map) {
    if (map != null) {

        // Set the map position
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(29,
                -88), 3.0f));

        // Add a marker on Washington, DC, USA
        map.addMarker(new MarkerOptions().position(
                new LatLng(38.8895, -77.0352)).title(
                getString(R.string.in_washington_string)));

        // Add a marker on Mexico City, Mexico
        map.addMarker(new MarkerOptions().position(
                new LatLng(19.13, -99.4)).title(
                getString(R.string.in_mexico_string)));
    }

}
 
Example 3
Source File: Clusterkraf.java    From clusterkraf with Apache License 2.0 6 votes vote down vote up
private void drawMarkers() {
	GoogleMap map = mapRef.get();
	if (map != null && currentClusters != null) {
		currentMarkers = new ArrayList<Marker>(currentClusters.size());
		currentClusterPointsByMarker = new HashMap<Marker, ClusterPoint>(currentClusters.size());
		MarkerOptionsChooser moc = options.getMarkerOptionsChooser();
		for (ClusterPoint clusterPoint : currentClusters) {
			MarkerOptions markerOptions = new MarkerOptions();
			markerOptions.position(clusterPoint.getMapPosition());
			if (moc != null) {
				moc.choose(markerOptions, clusterPoint);
			}
			Marker marker = map.addMarker(markerOptions);
			currentMarkers.add(marker);
			currentClusterPointsByMarker.put(marker, clusterPoint);
		}
	}
}
 
Example 4
Source File: LocationDisplayActivity.java    From NaviBee with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    this.googleMap = googleMap;
    LatLng location = new LatLng(lat, lon);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) !=
                PackageManager.PERMISSION_GRANTED &&
                checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) !=
                        PackageManager.PERMISSION_GRANTED)) {
            googleMap.setMyLocationEnabled(true);
        }
    }
    googleMap.setPadding(0, getStatusBarHeight(mapView), 0, 0);

    googleMap.getUiSettings().setMapToolbarEnabled(false);

    googleMap.addMarker(new MarkerOptions().position(location));
    googleMap.moveCamera(CameraUpdateFactory.zoomTo(DEFAULT_ZOOM_LEVEL));
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(location));
}
 
Example 5
Source File: AbstractDetailActivity.java    From google-io-2014-compat with Apache License 2.0 6 votes vote down vote up
private void setupMap() {
    final GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    double lat = getIntent().getDoubleExtra("lat", 37.6329946);
    double lng = getIntent().getDoubleExtra("lng", -122.4938344);
    float zoom = getIntent().getFloatExtra("zoom", 15);

    LatLng position = new LatLng(lat, lng);
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(position, zoom));
    map.addMarker(new MarkerOptions().position(position));

    // We need the snapshot of the map to prepare the shader for the circular reveal.
    // So the map is visible on activity start and then once the snapshot is taken, quickly hidden.
    map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            map.snapshot(new GoogleMap.SnapshotReadyCallback() {
                @Override
                public void onSnapshotReady(Bitmap bitmap) {
                    mapLoaded(bitmap);
                }
            });
        }
    });
}
 
Example 6
Source File: CardActivity.java    From Walrus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    LatLng latLng = new LatLng(card.cardLocationLat, card.cardLocationLng);

    googleMap.addMarker(new MarkerOptions().position(latLng));
    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
}
 
Example 7
Source File: ClusterTransitionsAnimation.java    From clusterkraf with Apache License 2.0 5 votes vote down vote up
private Marker addMarker(GoogleMap map, MarkerOptionsChooser moc, ClusterPoint clusterPoint) {
	MarkerOptions mo = new MarkerOptions();
	mo.position(clusterPoint.getMapPosition());
	if (moc != null) {
		moc.choose(mo, clusterPoint);
	}
	return map.addMarker(mo);
}
 
Example 8
Source File: PPTGoogleMapManager.java    From react-native-maps with MIT License 5 votes vote down vote up
/**
 * Places the default red marker on the map at the required position.
 *
 * @param googleMap
 * @param latLng
 */
private void markerWithDefaultIcon(GoogleMap googleMap, LatLng latLng, String publicId)
{
    MarkerOptions options = new MarkerOptions();

    options.position(latLng);

    Marker marker = googleMap.addMarker(options);

    publicMarkerIds.put(marker.getId(), publicId);
}
 
Example 9
Source File: MapsActivity.java    From ScreenshotsNanny with MIT License 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    LatLng berlin = new LatLng(mBerlinLat, mBerlinLng);
    Marker marker = googleMap.addMarker(new MarkerOptions().position(berlin).title(getString(R.string.map_marker_title)));
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(berlin));
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(mBerlinZoomLevel));
    mEditTextLat.setText(String.valueOf(marker.getPosition().latitude));
    mEditTextLng.setText(String.valueOf(marker.getPosition().longitude));
}
 
Example 10
Source File: MapsActivity.java    From LearningAppAndroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Configures the google map
 * In case there is GeoLocations or Beacons
 *
 * @param map Google map to work on
 */
private void setUpMap(GoogleMap map) {
    MCLocationManager lm = MCLocationManager.getInstance();

    /* lastCoordinate is the location which the map will show, the default being San Francisco */
    LatLng lastCoordinate = new LatLng(Double.parseDouble(getResources().getString(R.string.default_latitude)),
            Double.parseDouble(getResources().getString(R.string.default_longitude)));

    /* Loops through the beacons and set them in the map */
    for (MCBeacon beacon : lm.getBeacons()) {
        map.addMarker(new MarkerOptions()
                .position(beacon.getCoordenates())
                .title(beacon.getName())
                .icon(BitmapDescriptorFactory.fromResource((R.drawable.tags))));
        map.addCircle(new CircleOptions()
                .center(beacon.getCoordenates())
                .radius(beacon.getRadius())
                .strokeColor(getResources().getColor(R.color.beaconOuterCircle))
                .fillColor(getResources().getColor(R.color.beaconInnerCircle)));
        lastCoordinate = beacon.getCoordenates();
    }

    /* Loops through the locations and set them in the map */
    for (MCGeofence location : lm.getGeofences()) {
        map.addMarker(new MarkerOptions().position(location.getCoordenates()).title(location.getName()));
        map.addCircle(new CircleOptions()
                .center(location.getCoordenates())
                .radius(location.getRadius())
                .strokeColor(getResources().getColor(R.color.geoLocationOuterCircle))
                .fillColor(getResources().getColor(R.color.geoLocationInnerCircle)));
        lastCoordinate = location.getCoordenates();
    }
    /* Centers the map in the last coordinate found and sets the zoom */
    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(lastCoordinate).zoom(getResources().getInteger(R.integer.map_zoom)).build();
    map.animateCamera(CameraUpdateFactory
            .newCameraPosition(cameraPosition));
}
 
Example 11
Source File: MainActivity.java    From xposed-gps with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	settings = new Settings(getApplicationContext());
	FragmentManager fm = getFragmentManager();
	Fragment frag = fm.findFragmentById(R.id.map);
	if (frag instanceof MapFragment) {
		MapFragment mapf = (MapFragment) frag;
		mMap = (GoogleMap) mapf.getMap();
		mMap.setOnCameraChangeListener(this);
		mMarker = new MarkerOptions();
		mInit = new LatLng(settings.getLat(), settings.getLng());
		mMarker.position(mInit);
		mMarker.draggable(true);

		CameraUpdate cam = CameraUpdateFactory.newLatLng(mInit);
		mMap.moveCamera(cam);
		mMap.addMarker(mMarker);
	}

	Button set   = (Button) findViewById(R.id.set_location);
	set.setOnClickListener(this);
	Button start = (Button) findViewById(R.id.start);
	start.setOnClickListener(this);
	Button sel   = (Button) findViewById(R.id.select_apps);
	sel.setOnClickListener(this);

	start.setText(settings.isStarted() ? getString(R.string.stop) : getString(R.string.start));
}
 
Example 12
Source File: MapDialogFragment.java    From openshop.io-android with MIT License 5 votes vote down vote up
@Override
    public void onMapReady(GoogleMap googleMap) {
        if (branch != null && branch.getCoordinates() != null) {
            LatLng position = new LatLng(branch.getCoordinates().getLat(), branch.getCoordinates().getLon());
            googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 13));
            googleMap.addMarker(new MarkerOptions()
//                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.shop_info_map_mrker))
                    .title(branch.getName())
                    .snippet(branch.getAddress())
                    .position(position)
                    .draggable(false)
                    .anchor((float) 0.917, (float) 0.903));
        }
    }
 
Example 13
Source File: MapActivity.java    From android-map_list with MIT License 5 votes vote down vote up
public void onMapReady(GoogleMap map) {
    double lat = getIntent().getDoubleExtra(EXTRA_LATITUDE, 0);
    double lng = getIntent().getDoubleExtra(EXTRA_LONGITUDE, 0);

    map.addMarker(new MarkerOptions().position(new LatLng(lat, lng)));

    LatLng coords = new LatLng(lat, lng);
    map.addMarker(new MarkerOptions().position(coords));
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(coords, 10f);
    map.moveCamera(cameraUpdate);
}
 
Example 14
Source File: MainActivity.java    From PokeFaker with MIT License 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    if (mMap == null) {
        mMap = googleMap;
        setMap(mMap);
    }

    mMarkerOpts = new MarkerOptions().position(new LatLng(0, 0));
    mMarker = googleMap.addMarker(mMarkerOpts);
    fetchSavedLocation();
    if (!(mMarker.getPosition().latitude == 0.0 && mMarker.getPosition().longitude == 0.0)) {
        moveCamera(true);
    }
}
 
Example 15
Source File: MainActivity.java    From ExamplesAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    // Add a marker in Sydney, Australia, and move the camera.

    LatLng lugar = new LatLng(19.4112431, -99.2091994);//creamos una #localizacion#
    googleMap.addMarker(new MarkerOptions().position(lugar).title("Saludos desde Mexico"));//creamos una marca en el mapa "lugar"
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(lugar));//Movemos la camara en la localizacion "lugar" asignado

}
 
Example 16
Source File: ProfileActivity.java    From mage-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onMapReady(GoogleMap map) {
	SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
	map.setMapType(preferences.getInt(getString(R.string.baseLayerKey), getResources().getInteger(R.integer.baseLayerDefaultValue)));

	int dayNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
	if (dayNightMode == Configuration.UI_MODE_NIGHT_NO) {
		map.setMapStyle(null);
	} else {
		map.setMapStyle(MapStyleOptions.loadRawResourceStyle(getApplicationContext(), R.raw.map_theme_night));
	}


	if (latLng != null && icon != null) {
		map.addMarker(new MarkerOptions()
			.position(latLng)
			.icon(icon));

		LocationProperty accuracyProperty = location.getPropertiesMap().get("accuracy");
		if (accuracyProperty != null) {
			float accuracy = Float.parseFloat(accuracyProperty.getValue().toString());

			int color = LocationBitmapFactory.locationColor(getApplicationContext(), location);
			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));

			double latitudePadding = (accuracy / 111325);
			LatLngBounds bounds = new LatLngBounds(
					new LatLng(latLng.latitude - latitudePadding, latLng.longitude),
					new LatLng(latLng.latitude + latitudePadding, latLng.longitude));

			int minDimension = Math.min(mapView.getWidth(), mapView.getHeight());
			int padding = (int) Math.floor(minDimension / 5f);
			map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, padding));
		} else {
			map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17));
		}
	}
}
 
Example 17
Source File: RetainMapDemoActivity.java    From android-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onMapReady(GoogleMap map) {
    map.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
 
Example 18
Source File: ProgrammaticDemoActivity.java    From android-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onMapReady(GoogleMap map) {
    map.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
 
Example 19
Source File: MapUtils.java    From android-rxgeofence with MIT License 4 votes vote down vote up
public static Marker addMarker(GoogleMap googleMap, String name, double latitude,
    double longitude) {
  return googleMap.addMarker(new MarkerOptions().position(
      new LatLng(latitude, longitude)
  ).title(name));
}
 
Example 20
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 2 votes vote down vote up
/**
 * Add a LatLng to the map
 *
 * @param map     google map
 * @param latLng  lat lng
 * @param options marker options
 * @return marker
 */
public static Marker addLatLngToMap(GoogleMap map, LatLng latLng,
                                    MarkerOptions options) {
    return map.addMarker(options.position(latLng));
}