Java Code Examples for com.google.android.gms.maps.model.MarkerOptions#position()

The following examples show how to use com.google.android.gms.maps.model.MarkerOptions#position() . 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: MarkerActivity.java    From Complete-Google-Map-API-Tutorial with Apache License 2.0 6 votes vote down vote up
private void addMarkersToMap()
{
	MarkerOptions options =new MarkerOptions();
	options.position(BRISBANE);
	options.title("brisbane");
	options.snippet("Population: 2,544,634");
	options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
	options.draggable(true);
	CustomInfoWindowAdapter.brisbane=googleMap.addMarker(options);


	MarkerOptions options2 =new MarkerOptions();
	options2.position(ADELAIDE);
	options2.title("adelaide");
	options2.snippet("Population: 3,543,222");
	Drawable drawable=ContextCompat.getDrawable(getApplicationContext(),R.drawable.ic_person_pin_circle_black_24dp);
	options2.icon(convertDrawableToBitmap(drawable));
	options2.draggable(true);
	CustomInfoWindowAdapter.adelaide=googleMap.addMarker(options2);
}
 
Example 2
Source File: GetNearbyPlacesData.java    From BloodBank with GNU General Public License v3.0 6 votes vote down vote up
private void showNearbyPlaces(List<HashMap<String, String>> nearbyplaces)
{
    for(int i=0; i<nearbyplaces.size(); i++)
    {
        MarkerOptions markerOptions = new MarkerOptions();
        HashMap<String, String> googlePlace = nearbyplaces.get(i);

        String PlaceName = googlePlace.get("place_name");
        String vicinity = googlePlace.get("vicinity");
        double lat = Double.parseDouble(googlePlace.get("lat"));
        double lng = Double.parseDouble(googlePlace.get("lng"));

        LatLng latLng = new LatLng(lat, lng);
        markerOptions.position(latLng);
        markerOptions.title(PlaceName+" "+vicinity);
        markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));

        mMap.addMarker(markerOptions);
        mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        mMap.animateCamera(CameraUpdateFactory.zoomBy(10));
    }
}
 
Example 3
Source File: MainActivity.java    From Android-GSDemo-GoogleMap with MIT License 6 votes vote down vote up
private void updateDroneLocation(){

        LatLng pos = new LatLng(droneLocationLat, droneLocationLng);
        //Create MarkerOptions object
        final MarkerOptions markerOptions = new MarkerOptions();
        markerOptions.position(pos);
        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.aircraft));

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (droneMarker != null) {
                    droneMarker.remove();
                }

                if (checkGpsCoordination(droneLocationLat, droneLocationLng)) {
                    droneMarker = gMap.addMarker(markerOptions);
                }
            }
        });
    }
 
Example 4
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 5
Source File: MapWrapper.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
@Override
public void addMarker(final Marker aMarker) {
	final MarkerOptions marker = new MarkerOptions();
	marker.position(new LatLng(aMarker.latitude, aMarker.longitude));
	if (!TextUtils.isEmpty(aMarker.title)) {
		marker.title(aMarker.title);
	}
	if (!TextUtils.isEmpty(aMarker.snippet)) {
		marker.snippet(aMarker.snippet);
	}
	if (aMarker.bitmap != null) {
		marker.icon(BitmapDescriptorFactory.fromBitmap(aMarker.bitmap));
	} else {
		if (aMarker.icon != 0) {
			marker.icon(BitmapDescriptorFactory.fromResource(aMarker.icon));
		}
	}
	if (aMarker.anchor == Marker.Anchor.CENTER) {
		marker.anchor(0.5f, 0.5f);
	}
	mGoogleMap.addMarker(marker);
}
 
Example 6
Source File: MapObservationManager.java    From mage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Add a shape marker to the map at the location.  A shape marker is a transparent icon for allowing shape info windows.
 *
 * @param latLng  lat lng location
 * @param visible visible state
 * @return shape marker
 */
public Marker addShapeMarker(LatLng latLng, boolean visible) {

    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)));
    markerOptions.visible(visible);
    markerOptions.anchor(0.5f, 0.5f);
    markerOptions.position(latLng);
    Marker marker = map.addMarker(markerOptions);

    return marker;
}
 
Example 7
Source File: MapObservationManager.java    From mage-android with Apache License 2.0 5 votes vote down vote up
/**
 * Add an observation to the map as a marker or shape
 *
 * @param observation observation
 * @param markerOptions marker options
 * @param visible     visible state
 * @return map observation
 */
public MapObservation addToMap(Observation observation, MarkerOptions markerOptions, boolean visible) {

    MapObservation observationShape = null;

    Geometry geometry = observation.getGeometry();

    if (geometry.getGeometryType() == GeometryType.POINT) {
        Point point = GeometryUtils.getCentroid(geometry);
        if(markerOptions == null) {
            markerOptions = getMarkerOptions(observation, visible);
            markerOptions.position(new LatLng(point.getY(), point.getX()));
        }
        Marker marker = map.addMarker(markerOptions);

        observationShape = new MapMarkerObservation(observation, marker);
    } else {

        GoogleMapShapeConverter shapeConverter = new GoogleMapShapeConverter();
        GoogleMapShape shape = shapeConverter.toShape(geometry);
        prepareShapeOptions(observation, shape, visible);
        GoogleMapShape mapShape = GoogleMapShapeConverter.addShapeToMap(map, shape);

        observationShape = MapShapeObservation.create(observation, mapShape);
    }

    return observationShape;
}
 
Example 8
Source File: MainActivity.java    From Android-GSDemo-GoogleMap with MIT License 5 votes vote down vote up
private void markWaypoint(LatLng point){
    //Create MarkerOptions object
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(point);
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
    Marker marker = gMap.addMarker(markerOptions);
    mMarkers.put(mMarkers.size(), marker);
}
 
Example 9
Source File: MarkerImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
public MarkerImpl(String id, MarkerOptions options, MarkupListener listener) {
    this.id = id;
    this.listener = listener;
    this.options = options == null ? new MarkerOptions() : options;
    if (options.getPosition() == null) {
        options.position(new LatLng(0, 0));
    }
    icon = options.getIcon() == null ? null : new BitmapDescriptorImpl(options.getIcon());
    Log.d(TAG, "New marker " + id + " with title " + options.getTitle() + " @ " +
            options.getPosition());
}
 
Example 10
Source File: MapMarker.java    From android-app with GNU General Public License v2.0 5 votes vote down vote up
private MarkerOptions getMarker(Spot spot, float hueColor, Itinerary itinerary) {
    MarkerOptions options = new MarkerOptions();
    LatLng position = new LatLng(spot.getLatitude(), spot.getLongitude());
    options.position(position);
    options.anchor(0.0f, 1.0f);
    options.icon(BitmapDescriptorFactory.defaultMarker(hueColor));
    options.snippet(new Gson().toJson(itinerary)+">"+spot.getReturning());
    return options;
}
 
Example 11
Source File: MainActivity.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
/**
 * 戦場1つを描画する
 */
private void drawField(Field field) {
    // マーカー定義
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.title(field.getName()); // 名前を設定
    markerOptions.snippet(field.getMemo()); // 説明を設定
    markerOptions.position(calcCenter(field.getVertexes())); // マーカーの座標を設定(区画の中心を自動算出)
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(field.getColorHue())); // 色を設定

    // マップにマーカーを追加
    mGoogleMap.addMarker(markerOptions);

    // 区画を描画
    final LatLng[] vertexes = field.getVertexes();
    if (vertexes != null && vertexes.length > 3) {
        // ポリゴン定義
        PolygonOptions polygonOptions = new PolygonOptions();

        // RGBそれぞれの色を作成
        final int[] colorRgb = field.getColorRgb();
        int colorRed = colorRgb[0];
        int colorGreen = colorRgb[1];
        int colorBlue = colorRgb[2];

        // 区画の輪郭について設定
        polygonOptions.strokeColor(Color.argb(0x255, colorRed, colorGreen, colorBlue));
        polygonOptions.strokeWidth(5);

        // 区画の塗りつぶしについて設定
        polygonOptions.fillColor(Color.argb(0x40, colorRed, colorGreen, colorBlue));

        // 各頂点の座標を設定
        polygonOptions.add(vertexes); // LatLngでもLatLng[]でもOK

        // マップにポリゴンを追加
        mGoogleMap.addPolygon(polygonOptions);
    }
}
 
Example 12
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 13
Source File: DistanceAction.java    From Companion-For-PUBG-Android with MIT License 5 votes vote down vote up
/**
 * Helper function.
 *
 * @param latLng position on {@link GoogleMap} to create a marker.
 * @return marker on map.
 */
@NonNull
private Marker addMarker(@NonNull final LatLng latLng) {
    final MarkerOptions options = createMarkerOptions();
    options.position(latLng);
    return this.mapController.addMarker(options);
}
 
Example 14
Source File: VehicleAction.java    From Companion-For-PUBG-Android with MIT License 5 votes vote down vote up
@Override
protected void onToggleAction() {
    if (shouldShow()) {
        for (final LatLng latLng : this.vehicleSpawns) {
            final MarkerOptions markerOptions = createMarkerOptions();
            markerOptions.position(latLng);
            this.vehicleMarkers.add(this.mapController.addMarker(markerOptions));
        }
    } else {
        for (final Marker marker : this.vehicleMarkers) {
            marker.remove();
        }
        this.vehicleMarkers.clear();
    }
}
 
Example 15
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 16
Source File: MapActivity.java    From Bus-Tracking-Parent with GNU General Public License v3.0 5 votes vote down vote up
private void addMarker(LatLng location, String time) {
    if (mGoogleMap != null) {
        MarkerOptions mMarkerOption = new MarkerOptions();
        mMarkerOption.position(location);
        mMarkerOption.title("Bus is here");
        mMarkerOption.snippet(time);
        mMarkerOption.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_directions_bus_black_24dp));
        removeMarker();
        mMarker = mGoogleMap.addMarker(mMarkerOption);
    }
}
 
Example 17
Source File: NearByHospitalActivity.java    From BloodBank with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onLocationChanged(Location location) {
    lastlocation = location;
    LatLng latLng = new LatLng(location.getLatitude() , location.getLongitude());
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title("Current Location");
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
    currentLocationmMarker = mMap.addMarker(markerOptions);
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    mMap.animateCamera(CameraUpdateFactory.zoomBy(0));

}
 
Example 18
Source File: LocationGeofenceEditorActivity.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
private void updateEditedMarker(boolean setMapCamera) {
    if (mMap != null) {

        if (mLastLocation != null) {
            LatLng lastLocationGeofence = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());
            if (lastLocationRadius == null) {
                lastLocationRadius = mMap.addCircle(new CircleOptions()
                        .center(lastLocationGeofence)
                        .radius(mLastLocation.getAccuracy())
                        .strokeColor(ContextCompat.getColor(this, R.color.map_last_location_marker_stroke))
                        .fillColor(ContextCompat.getColor(this, R.color.map_last_location_marker_fill))
                        .strokeWidth(5)
                        .zIndex(1));
            } else {
                lastLocationRadius.setRadius(mLastLocation.getAccuracy());
                lastLocationRadius.setCenter(lastLocationGeofence);
            }
        }

        if (mLocation != null) {
            LatLng editedGeofence = new LatLng(mLocation.getLatitude(), mLocation.getLongitude());
            if (editedMarker == null) {
                MarkerOptions markerOptions = new MarkerOptions();
                markerOptions.position(editedGeofence);
                editedMarker = mMap.addMarker(markerOptions);
            } else
                editedMarker.setPosition(editedGeofence);
            editedMarker.setTitle(geofenceNameEditText.getText().toString());

            if (editedRadius == null) {
                editedRadius = mMap.addCircle(new CircleOptions()
                        .center(editedGeofence)
                        .radius(geofence._radius)
                        .strokeColor(ContextCompat.getColor(this, R.color.map_edited_location_marker_stroke))
                        .fillColor(ContextCompat.getColor(this, R.color.map_edited_location_marker_fill))
                        .strokeWidth(5)
                        .zIndex(2));
            } else {
                editedRadius.setRadius(geofence._radius);
                editedRadius.setCenter(editedGeofence);
            }
            radiusValue.setText(String.valueOf(Math.round(geofence._radius)));

            if (setMapCamera) {
                if (editedRadius != null) {
                    try {
                        float zoom = getCircleZoomValue(mLocation.getLatitude(), mLocation.getLongitude(), geofence._radius,
                                                            mMap.getMinZoomLevel(), mMap.getMaxZoomLevel());
                        //PPApplication.logE("LocationGeofenceEditorActivity.updateEditedMarker", "zoom=" + zoom);
                        if (zoom > 16)
                            zoom = 16;
                        mMap.animateCamera(CameraUpdateFactory.zoomTo(zoom));//, 1000, null);
                    } catch (StackOverflowError e) {
                        mMap.moveCamera(CameraUpdateFactory.newLatLng(editedGeofence));
                    }
                }
                else {
                    mMap.moveCamera(CameraUpdateFactory.newLatLng(editedGeofence));
                }
            }
        }
    }
    //else {
    //    Log.e("LocationGeofenceEditorActivity.updateEditedMarker", "mMap==null");
    //}
}
 
Example 19
Source File: MapObservationManager.java    From mage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Prepare the shape options for an observation shape
 *
 * @param observation observation
 * @param shape       shape
 * @param visible     visible flag
 */
private void prepareShapeOptions(Observation observation, GoogleMapShape shape, boolean visible) {

    ObservationShapeStyle style = ObservationShapeStyleParser.getStyle(context, observation);

    GoogleMapShapeType shapeType = shape.getShapeType();
    switch (shapeType) {

        case LAT_LNG:
            LatLng latLng = (LatLng) shape.getShape();
            MarkerOptions markerOptions = getMarkerOptions(observation, visible);
            markerOptions.position(latLng);
            shape.setShape(markerOptions);
            shape.setShapeType(GoogleMapShapeType.MARKER_OPTIONS);
            break;

        case POLYLINE_OPTIONS:
            PolylineOptions polylineOptions = (PolylineOptions) shape
                    .getShape();
            setPolylineOptions(style, polylineOptions, visible);
            break;

        case POLYGON_OPTIONS:
            PolygonOptions polygonOptions = (PolygonOptions) shape.getShape();
            setPolygonOptions(style, polygonOptions, visible);
            break;

        case MULTI_LAT_LNG:
            MultiLatLng multiLatLng = (MultiLatLng) shape.getShape();
            MarkerOptions sharedMarkerOptions = getMarkerOptions(observation, visible);
            multiLatLng.setMarkerOptions(sharedMarkerOptions);
            break;

        case MULTI_POLYLINE_OPTIONS:
            MultiPolylineOptions multiPolylineOptions = (MultiPolylineOptions) shape
                    .getShape();
            PolylineOptions sharedPolylineOptions = new PolylineOptions();
            setPolylineOptions(style, sharedPolylineOptions, visible);
            multiPolylineOptions.setOptions(sharedPolylineOptions);
            break;

        case MULTI_POLYGON_OPTIONS:
            MultiPolygonOptions multiPolygonOptions = (MultiPolygonOptions) shape
                    .getShape();
            PolygonOptions sharedPolygonOptions = new PolygonOptions();
            setPolygonOptions(style, sharedPolygonOptions, visible);
            multiPolygonOptions.setOptions(sharedPolygonOptions);
            break;

        case COLLECTION:
            @SuppressWarnings("unchecked")
            List<GoogleMapShape> shapes = (List<GoogleMapShape>) shape
                    .getShape();
            for (int i = 0; i < shapes.size(); i++) {
                prepareShapeOptions(observation, shapes.get(i), visible);
            }
            break;
        default:
    }
}
 
Example 20
Source File: MapActivity.java    From Bus-Tracking-Parent with GNU General Public License v3.0 4 votes vote down vote up
private void forRecentRide() {
    // get details from intent
    String start_gps = getIntent().getStringExtra("start_gps");
    String end_gps = getIntent().getStringExtra("end_gps");
    String start_time = getIntent().getStringExtra("start_time");
    String end_time = getIntent().getStringExtra("end_time");
    String current_gps = getIntent().getStringExtra("current_gps");

    LatLong sGps = new LatLong(start_gps);
    LatLong eGps = new LatLong(end_gps);
    LatLong cGps = new LatLong(current_gps);
    if (sGps.isValid()) {
        start_time = DateTimeUtils.getTime(start_time);
        end_time = DateTimeUtils.getTime(end_time);
        MarkerOptions s_options = new MarkerOptions();
        s_options.position(new LatLng(sGps.getLat(), sGps.getLon()));
        s_options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE));
        s_options.title("Started :" + start_time);
        s_options.snippet(LocationHelper.getLocationName(this, sGps.getLat(), sGps.getLon()));
        addCustomMarker(s_options);
        if (eGps.isValid()) {
            // draw line
            //addLine(new LatLng(sGps.getLat(), sGps.getLat()), new LatLng(eGps.getLat(), eGps.getLon()));

            MarkerOptions e_options = new MarkerOptions();
            e_options.position(new LatLng(eGps.getLat(), eGps.getLon()));
            e_options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
            e_options.title("Completed :" + end_time);
            e_options.snippet(LocationHelper.getLocationName(this, eGps.getLat(), eGps.getLon()));
            addCustomMarker(e_options);
        } else if (cGps.isValid()) {
            // draw line
            //addLine(new LatLng(cGps.getLat(), cGps.getLat()), new LatLng(sGps.getLat(), sGps.getLon()));

            MarkerOptions c_options = new MarkerOptions();
            c_options.position(new LatLng(cGps.getLat(), cGps.getLon()));
            c_options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
            c_options.title("Incomplete ?");
            c_options.snippet(LocationHelper.getLocationName(this, cGps.getLat(), cGps.getLon()));
            addCustomMarker(c_options);
        }
    }
}