com.google.android.gms.maps.model.MarkerOptions Java Examples

The following examples show how to use com.google.android.gms.maps.model.MarkerOptions. 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 void populateMulti(final MultiAdapter adapter) {
    map.clear();
    allMarkers = new LinkedList<>();
    for (int page = 0; page < adapter.getCount(); page++) {
        LinkedList<Marker> pageMarkers = new LinkedList<>();
        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) {
                    MarkerOptions mo = createMarkerOptions(cp, adapter.getMarkerTitle(page, i));
                    pageMarkers.add(map.addMarker(mo));
                }
                else pageMarkers.add(null);
            }
        }
        allMarkers.add(pageMarkers);
    }
    map.setOnMarkerClickListener(createMarkerClickListenerMulti(adapter));
    initDefaultPositions(adapter);
}
 
Example #2
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Add a MultiPolylineOptions to the map as markers
 *
 * @param shapeMarkers          google map shape markers
 * @param map                   google map
 * @param multiPolyline         multi polyline options
 * @param polylineMarkerOptions polyline marker options
 * @param globalPolylineOptions global polyline options
 * @return multi polyline markers
 */
public MultiPolylineMarkers addMultiPolylineToMapAsMarkers(
        GoogleMapShapeMarkers shapeMarkers, GoogleMap map,
        MultiPolylineOptions multiPolyline,
        MarkerOptions polylineMarkerOptions,
        PolylineOptions globalPolylineOptions) {
    MultiPolylineMarkers polylines = new MultiPolylineMarkers();
    for (PolylineOptions polylineOptions : multiPolyline
            .getPolylineOptions()) {
        PolylineMarkers polylineMarker = addPolylineToMapAsMarkers(map,
                polylineOptions, polylineMarkerOptions,
                globalPolylineOptions);
        shapeMarkers.add(polylineMarker);
        polylines.add(polylineMarker);
    }
    return polylines;
}
 
Example #3
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 #4
Source File: CircleDemoActivity.java    From android-samples with Apache License 2.0 6 votes vote down vote up
public DraggableCircle(LatLng center, double radiusMeters) {
    this.radiusMeters = radiusMeters;
    centerMarker = map.addMarker(new MarkerOptions()
            .position(center)
            .draggable(true));
    radiusMarker = map.addMarker(new MarkerOptions()
            .position(toRadiusLatLng(center, radiusMeters))
            .draggable(true)
            .icon(BitmapDescriptorFactory.defaultMarker(
                    BitmapDescriptorFactory.HUE_AZURE)));
    circle = map.addCircle(new CircleOptions()
            .center(center)
            .radius(radiusMeters)
            .strokeWidth(strokeWidthBar.getProgress())
            .strokeColor(strokeColorArgb)
            .fillColor(fillColorArgb)
            .clickable(clickabilityCheckbox.isChecked()));
}
 
Example #5
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 #6
Source File: StyleUtils.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Set the icon into the marker options
 *
 * @param markerOptions marker options
 * @param icon          icon row
 * @param density       display density: {@link android.util.DisplayMetrics#density}
 * @param iconCache     icon cache
 * @return true if icon was set into the marker options
 */
public static boolean setIcon(MarkerOptions markerOptions, IconRow icon, float density, IconCache iconCache) {

    boolean iconSet = false;

    if (icon != null) {

        Bitmap iconImage = createIcon(icon, density, iconCache);
        markerOptions.icon(BitmapDescriptorFactory
                .fromBitmap(iconImage));
        iconSet = true;

        double anchorU = icon.getAnchorUOrDefault();
        double anchorV = icon.getAnchorVOrDefault();

        markerOptions.anchor((float) anchorU, (float) anchorV);
    }

    return iconSet;
}
 
Example #7
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 #8
Source File: BusinessDetailsActivity.java    From YelpQL with MIT License 6 votes vote down vote up
private void showPointerOnMap(final double latitude, final double longitude) {
    mvRestaurantLocation.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {
            LatLng latLng = new LatLng(latitude, longitude);
            googleMap.addMarker(new MarkerOptions()
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_flag))
                    .anchor(0.0f, 1.0f)
                    .position(latLng));
            googleMap.getUiSettings().setMyLocationButtonEnabled(false);
            googleMap.getUiSettings().setZoomControlsEnabled(true);

            // Updates the location and zoom of the MapView
            CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 15);
            googleMap.moveCamera(cameraUpdate);
        }
    });
}
 
Example #9
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 #10
Source File: GglMapAiPoint2PointManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void addPointLatLng(LatLng latLng, float distance, LatLng deviceLocation) {
    if (this.pointMarker == null) {
        this.mp = new MapPointLatLng();
        this.mp.altitude = 5.0f;
        if (StateManager.getInstance().getX8Drone().isConnect()) {
            int h = Math.round(StateManager.getInstance().getX8Drone().getHeight());
            if (h > 5) {
                this.mp.altitude = (float) h;
            }
        }
        this.pointMarker = this.googleMap.addMarker(new MarkerOptions().position(latLng).icon(new GglMapCustomMarkerView().createCustomMarkerViewForP2P(this.context, R.drawable.x8_img_ai_follow_point2, this.mp.altitude, this.mp.nPos)).anchor(0.5f, 0.9f).draggable(false));
        this.pointMarker.setDraggable(true);
        this.pointMarker.setTag(this.mp);
    } else {
        this.pointMarker.setPosition(latLng);
    }
    drawPointLine(deviceLocation);
    this.mp.distance = distance;
    if (this.point2PointMarkerSelectListener != null) {
        this.point2PointMarkerSelectListener.onMarkerSelect(true, this.mp.altitude, this.mp, false);
    }
    this.isFollow = true;
}
 
Example #11
Source File: MapsEarthquakeMapActivity.java    From coursera-android with MIT License 6 votes vote down vote up
private void placeMarkers() {

        // Add a marker for every earthquake
        for (EarthQuakeRec rec : mRetainedFragment.getData()) {

            // Add a new marker for this earthquake
            mMap.addMarker(new MarkerOptions()

                    // Set the Marker's position
                    .position(new LatLng(rec.getLat(), rec.getLng()))

                    // Set the title of the Marker's information window
                    .title(String.valueOf(rec.getMagnitude()))

                    // Set the color for the Marker
                    .icon(BitmapDescriptorFactory
                            .defaultMarker(getMarkerColor(rec
                                    .getMagnitude()))));

        }
    }
 
Example #12
Source File: MarkerCloseInfoWindowOnRetapDemoActivity.java    From android-samples with Apache License 2.0 6 votes vote down vote up
private void addMarkersToMap() {
   mMap.addMarker(new MarkerOptions()
            .position(BRISBANE)
            .title("Brisbane")
            .snippet("Population: 2,074,200"));

    mMap.addMarker(new MarkerOptions()
            .position(SYDNEY)
            .title("Sydney")
            .snippet("Population: 4,627,300"));

    mMap.addMarker(new MarkerOptions()
            .position(MELBOURNE)
            .title("Melbourne")
            .snippet("Population: 4,137,400"));

    mMap.addMarker(new MarkerOptions()
            .position(PERTH)
            .title("Perth")
            .snippet("Population: 1,738,800"));

    mMap.addMarker(new MarkerOptions()
            .position(ADELAIDE)
            .title("Adelaide")
            .snippet("Population: 1,213,000"));
}
 
Example #13
Source File: DriverMapActivity.java    From UberClone with MIT License 6 votes vote down vote up
private void getAssignedCustomerPickupLocation(){
    assignedCustomerPickupLocationRef = FirebaseDatabase.getInstance().getReference().child("customerRequest").child(customerId).child("l");
    assignedCustomerPickupLocationRefListener = assignedCustomerPickupLocationRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if(dataSnapshot.exists() && !customerId.equals("")){
                List<Object> map = (List<Object>) dataSnapshot.getValue();
                double locationLat = 0;
                double locationLng = 0;
                if(map.get(0) != null){
                    locationLat = Double.parseDouble(map.get(0).toString());
                }
                if(map.get(1) != null){
                    locationLng = Double.parseDouble(map.get(1).toString());
                }
                pickupLatLng = new LatLng(locationLat,locationLng);
                pickupMarker = mMap.addMarker(new MarkerOptions().position(pickupLatLng).title("pickup location").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_pickup)));
                getRouteToMarker(pickupLatLng);
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
 
Example #14
Source File: MapsMarkerActivity.java    From android-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Manipulates the map when it's available.
 * The API invokes this callback when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user receives a prompt to install
 * Play services inside the SupportMapFragment. The API invokes this method after the user has
 * installed Google Play services and returned to the app.
 */
// [END_EXCLUDE]
// [START maps_marker_on_map_ready_add_marker]
@Override
public void onMapReady(GoogleMap googleMap) {
    // [START_EXCLUDE silent]
    // Add a marker in Sydney, Australia,
    // and move the map's camera to the same location.
    // [END_EXCLUDE]
    LatLng sydney = new LatLng(-33.852, 151.211);
    googleMap.addMarker(new MarkerOptions()
        .position(sydney)
        .title("Marker in Sydney"));
    // [START_EXCLUDE silent]
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    // [END_EXCLUDE]
}
 
Example #15
Source File: MapFragment.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    longitude = getArguments().getDouble("longitude");
    latitude = getArguments().getDouble("latitude");


    final MapView map = new MapView(getActivity());

    map.onCreate(null);

    map.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {
            mapController = googleMap;
            googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title(""));
            googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                    new LatLng(latitude, longitude),
                    16));
            map.onResume();
        }
    });

    return map;

}
 
Example #16
Source File: ObservationTask.java    From mage-android with Apache License 2.0 6 votes vote down vote up
@Override
protected Void doInBackground(Observation... observations) {
    for (Observation o : observations) {
        boolean passesFilter = true;
        for (Filter filter : filters) {
            passesFilter = filter.passesFilter(o);
            if (!passesFilter) {
                break;
            }
        }

        if (passesFilter) {
            Geometry geometry = o.getGeometry();
            Point centroid = GeometryUtils.getCentroid(geometry);
            MarkerOptions options = new MarkerOptions().position(new LatLng(centroid.getY(), centroid.getX())).icon(ObservationBitmapFactory.bitmapDescriptor(context, o));
            publishProgress(new Pair<>(options, o));
        }
    }

    return null;
}
 
Example #17
Source File: MainActivity.java    From NYU-BusTracker-Android with Apache License 2.0 6 votes vote down vote up
private void updateMapWithNewBusLocations() {
    if (startStop == null || endStop == null) {
        mMap.clear();
        displayStopError();
        return;
    }
    List<Route> routesBetweenStartAndEnd = startStop.getRoutesTo(endStop);
    BusManager sharedManager = BusManager.getBusManager();
    for (Marker m : busesOnMap) {
        m.remove();
    }
    busesOnMap = new ArrayList<>();
    if (clickableMapMarkers == null)
        clickableMapMarkers = new HashMap<>();  // New set of buses means new set of clickable markers!
    for (Route r : routesBetweenStartAndEnd) {
        for (Bus b : sharedManager.getBuses()) {
            //if (BuildConfig.DEBUG) Log.v("BusLocations", "bus id: " + b.getID() + ", bus route: " + b.getRoute() + " vs route: " + r.getID());
            if (b.getRoute().equals(r.getID())) {
                Marker mMarker = mMap.addMarker(new MarkerOptions().position(b.getLocation()).icon(BitmapDescriptorFactory.fromBitmap(rotateBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_bus_arrow), b.getHeading()))).anchor(0.5f, 0.5f));
                clickableMapMarkers.put(mMarker.getId(), false);    // Unable to click on buses.
                busesOnMap.add(mMarker);
            }
        }
    }
}
 
Example #18
Source File: GglMapAiLineManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void resetSmallMakerByMap(Marker marker1, Marker marker2, int n) {
    MapPointLatLng mpl1 = (MapPointLatLng) marker1.getTag();
    MapPointLatLng mpl2 = (MapPointLatLng) marker2.getTag();
    LatLng[] latLng = this.mapCalcAngle.getLineLatLngInterval(marker1.getPosition(), marker2.getPosition(), 3);
    mpl2.setAngle(getPointAngle(mpl1, mpl2));
    float[] angleArray = new float[]{mpl2.showAngle, mpl2.showAngle};
    for (int i = 0; i < latLng.length; i++) {
        MapPointLatLng mpl = new MapPointLatLng();
        mpl.isSelect = true;
        mpl.setAngle(angleArray[i]);
        Marker mMarker = this.googleMap.addMarker(new MarkerOptions().position(latLng[i]).icon(this.gdCustemMarkerView.createPointWithSmallArrow(this.context, R.drawable.x8_ai_line_point_small1, mpl.showAngle, true)).anchor(0.5f, 0.5f).draggable(false));
        mMarker.setTag(mpl);
        mMarker.setFlat(true);
        this.arrowMarkerList.add(n + i, mMarker);
    }
}
 
Example #19
Source File: BarometerNetworkActivity.java    From PressureNet with GNU General Public License v3.0 6 votes vote down vote up
private void displayTemperatureFrame(int frame) {
	temperatureAnimationStep = frame;
	Iterator<TemperatureForecast> temperatureIterator = forecastRecents
			.iterator();
	int num = 0;
	mMap.clear();
	while (temperatureIterator.hasNext()) {
		TemperatureForecast forecast = temperatureIterator.next();
		try {
			MarkerOptions markerOpts = temperatureAnimationMarkerOptions.get(num);
			if (forecast.getForecastHour() == frame) {
				mMap.addMarker(markerOpts);
			}
		} catch(IndexOutOfBoundsException ioobe) {
			// 
		}
		num++;
	}
	
	updateAnimationTime("left", activeForecastStartTime, frame);
	
}
 
Example #20
Source File: MapsActivity.java    From Krishi-Seva with MIT License 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    //Initialize Google Play Services
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.ACCESS_FINE_LOCATION)
                == PackageManager.PERMISSION_GRANTED) {
            buildGoogleApiClient();
            mMap.setMyLocationEnabled(true);
        }
    }
    else {
        buildGoogleApiClient();
        mMap.setMyLocationEnabled(true);
    }
    googleMap.addMarker(new MarkerOptions().position(kochi)
            .title("Farmer Location"));
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(kochi));
    mMap.setOnMapClickListener(this);



}
 
Example #21
Source File: Home.java    From UberClone with MIT License 6 votes vote down vote up
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.getUiSettings().setZoomGesturesEnabled(true);
    mMap.setInfoWindowAdapter(new CustomInfoWindow(this));
    googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this, R.raw.uber_style_map));

    mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng latLng) {
            if(destinationMarker!=null)
                destinationMarker.remove();
            destinationMarker=mMap.addMarker(new MarkerOptions().position(latLng)
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_destination_marker))
                    .title("Destination"));
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15.0f));

            BottomSheetRiderFragment mBottomSheet=BottomSheetRiderFragment.newInstance(String.format("%f,%f", currentLat, currentLng),
                    String.format("%f,%f",latLng.latitude, latLng.longitude), true);
            mBottomSheet.show(getSupportFragmentManager(), mBottomSheet.getTag());
        }
    });
    mMap.setOnInfoWindowClickListener(this);
}
 
Example #22
Source File: AddMapActivity.java    From JalanJalan with Do What The F*ck You Want To Public License 6 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    if (location == null) {
        // get last location device
        location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
        if (mMap != null) {
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13));
            mMap.addMarker(new MarkerOptions()
                            .position(new LatLng(location.getLatitude(), location.getLongitude()))
                            .title("Starting Point")
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker))
            );
            lat = location.getLatitude();
            lng = location.getLongitude();

            Toast.makeText(this, "Lokasi kamu saat ini, sebagai patokan titik awal perjalanan kamu kak :')", Toast.LENGTH_LONG).show();
        }
    }

}
 
Example #23
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 #24
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 #25
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 #26
Source File: WhereAmIActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
@Override
public void onLocationResult(LocationResult locationResult) {
  Location location = locationResult.getLastLocation();
  if (location != null) {
    updateTextView(location);
  }

  if (location != null) {
    updateTextView(location);
    if (mMap != null) {
      LatLng latLng = new LatLng(location.getLatitude(),
        location.getLongitude());
      mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));

      Calendar c = Calendar.getInstance();
      String dateTime = DateFormat.format("MM/dd/yyyy HH:mm:ss",
                                          c.getTime()).toString();

      int markerNumber = mMarkers.size()+1;
      mMarkers.add(mMap.addMarker(new MarkerOptions()
                                    .position(latLng)
                                    .title(dateTime)
                                    .snippet("Marker #" + markerNumber +
                                               " @ " + dateTime)));

      List<LatLng> points = mPolyline.getPoints();
      points.add(latLng);
      mPolyline.setPoints(points);
    }
  }
}
 
Example #27
Source File: MainActivity.java    From video-tutorial-code with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	
	map  = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
	
	map.addMarker(new MarkerOptions().position(LOCATION_SURRREY).title("Find me here!"));
}
 
Example #28
Source File: LocationLoadTask.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {
	CloseableIterator<Location> iterator = null;
	try {
		iterator = iterator();
		while (iterator.hasNext() && !isCancelled()) {
			Location location = iterator.current();
			User user = location.getUser();
			if (user == null) {
				continue;
			}

			Point point = GeometryUtils.getCentroid(location.getGeometry());
			LatLng latLng = new LatLng(point.getY(), point.getX());
			MarkerOptions options = new MarkerOptions().position(latLng).icon(LocationBitmapFactory.bitmapDescriptor(context, location, user));

			publishProgress(new Pair<>(options, new Pair<>(location, user)));
		}
	} catch (SQLException e) {
		e.printStackTrace();
	} finally {
		if (iterator != null) {
			iterator.closeQuietly();
		}
	}

	return null;
}
 
Example #29
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 #30
Source File: FenceChooserActivity.java    From JCVD with MIT License 5 votes vote down vote up
@Override
public void onMapClick(LatLng latLng) {
    mLocation = latLng;
    if (mMarker != null) {
        mMarker.remove();
    }
    mMarker = mMap.addMarker(new MarkerOptions()
            .position(latLng));
}