Search in sources :

Example 1 with GoogleMap

use of com.google.android.gms.maps.GoogleMap in project google-io-2014 by romainguy.

the class DetailActivity method setupMap.

private void setupMap() {
    GoogleMap map = ((MapFragment) getFragmentManager().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.0f);
    LatLng position = new LatLng(lat, lng);
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(position, zoom));
    map.addMarker(new MarkerOptions().position(position));
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) GoogleMap(com.google.android.gms.maps.GoogleMap) MapFragment(com.google.android.gms.maps.MapFragment) LatLng(com.google.android.gms.maps.model.LatLng)

Example 2 with GoogleMap

use of com.google.android.gms.maps.GoogleMap in project android-maps-utils by googlemaps.

the class PolySimplifyDemoActivity method startDemo.

@Override
protected void startDemo() {
    GoogleMap mMap = getMap();
    // Original line
    List<LatLng> line = PolyUtil.decode(LINE);
    mMap.addPolyline(new PolylineOptions().addAll(line).color(Color.BLACK));
    getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(28.05870, -82.4090), 15));
    List<LatLng> simplifiedLine;
    /**
         * Simplified lines - increasing the tolerance will result in fewer points in the simplified
         * line
         */
    // meters
    double tolerance = 5;
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.RED - ALPHA_ADJUSTMENT));
    // meters
    tolerance = 20;
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.GREEN - ALPHA_ADJUSTMENT));
    // meters
    tolerance = 50;
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.MAGENTA - ALPHA_ADJUSTMENT));
    // meters
    tolerance = 500;
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.YELLOW - ALPHA_ADJUSTMENT));
    // meters
    tolerance = 1000;
    simplifiedLine = PolyUtil.simplify(line, tolerance);
    mMap.addPolyline(new PolylineOptions().addAll(simplifiedLine).color(Color.BLUE - ALPHA_ADJUSTMENT));
    // Triangle polygon - the polygon should be closed
    ArrayList<LatLng> triangle = new ArrayList<>();
    // Should match last point
    triangle.add(new LatLng(28.06025, -82.41030));
    triangle.add(new LatLng(28.06129, -82.40945));
    triangle.add(new LatLng(28.06206, -82.40917));
    triangle.add(new LatLng(28.06125, -82.40850));
    triangle.add(new LatLng(28.06035, -82.40834));
    triangle.add(new LatLng(28.06038, -82.40924));
    // Should match first point
    triangle.add(new LatLng(28.06025, -82.41030));
    mMap.addPolygon(new PolygonOptions().addAll(triangle).fillColor(Color.BLUE - ALPHA_ADJUSTMENT).strokeColor(Color.BLUE).strokeWidth(5));
    // Simplified triangle polygon
    // meters
    tolerance = 88;
    List simplifiedTriangle = PolyUtil.simplify(triangle, tolerance);
    mMap.addPolygon(new PolygonOptions().addAll(simplifiedTriangle).fillColor(Color.YELLOW - ALPHA_ADJUSTMENT).strokeColor(Color.YELLOW).strokeWidth(5));
    // Oval polygon - the polygon should be closed
    List<LatLng> oval = PolyUtil.decode(OVAL_POLYGON);
    mMap.addPolygon(new PolygonOptions().addAll(oval).fillColor(Color.BLUE - ALPHA_ADJUSTMENT).strokeColor(Color.BLUE).strokeWidth(5));
    // Simplified oval polygon
    // meters
    tolerance = 10;
    List simplifiedOval = PolyUtil.simplify(oval, tolerance);
    mMap.addPolygon(new PolygonOptions().addAll(simplifiedOval).fillColor(Color.YELLOW - ALPHA_ADJUSTMENT).strokeColor(Color.YELLOW).strokeWidth(5));
}
Also used : GoogleMap(com.google.android.gms.maps.GoogleMap) PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LatLng(com.google.android.gms.maps.model.LatLng) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions)

Example 3 with GoogleMap

use of com.google.android.gms.maps.GoogleMap in project HumaneApp by Ganesh1010.

the class MapActivity method onMapReady.

@Override
public void onMapReady(GoogleMap googleMap) {
    mGoogleMap = googleMap;
    mGoogleMap.setOnMyLocationButtonClickListener(this);
    mGoogleMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

        @Override
        public void onMapLongClick(LatLng latLng) {
            if (mCurrLocationMarker != null) {
                mCurrLocationMarker.remove();
            }
            latitude = latLng.latitude;
            longitude = latLng.longitude;
            location = new LatLng(latitude, longitude);
            mCurrLocationMarker = mGoogleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, latLng.longitude)).draggable(true).visible(true).title(getAaddress(latitude, longitude)));
            mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 17));
        }
    });
    mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    //Initialize Google Play Services
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            //Location Permission already granted
            buildGoogleApiClient();
            mGoogleMap.setMyLocationEnabled(true);
        } else {
            //Request Location Permission
            checkLocationPermission();
        }
    } else {
        buildGoogleApiClient();
        mGoogleMap.setMyLocationEnabled(true);
    }
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) GoogleMap(com.google.android.gms.maps.GoogleMap) LatLng(com.google.android.gms.maps.model.LatLng)

Example 4 with GoogleMap

use of com.google.android.gms.maps.GoogleMap in project NPSmiles by bmcglynn1.

the class ItemOneFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_contact_page, container, false);
    SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
    OnMapReadyCallback obj = new OnMapReadyCallback() {

        @Override
        public void onMapReady(GoogleMap googleMap) {
            mMap = googleMap;
            LatLng smiles = new LatLng(39.104729, -77.191294);
            mMap.addMarker(new MarkerOptions().position(smiles).title("North Potomac Smiles, LLC."));
            mMap.moveCamera(CameraUpdateFactory.newLatLng(smiles));
            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(smiles, 16));
        }
    };
    mapFragment.getMapAsync(obj);
    return view;
}
Also used : SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) GoogleMap(com.google.android.gms.maps.GoogleMap) OnMapReadyCallback(com.google.android.gms.maps.OnMapReadyCallback) LatLng(com.google.android.gms.maps.model.LatLng) View(android.view.View)

Example 5 with GoogleMap

use of com.google.android.gms.maps.GoogleMap in project android-maps-utils by googlemaps.

the class Layer method setOnFeatureClickListener.

/**
     * Sets a single click listener for the entire GoogleMap object, that will be called
     * with the corresponding Feature object when an object on the map (Polygon,
     * Marker, Polyline) is clicked.
     *
     * If getFeature() returns null this means that either the object is inside a KMLContainer,
     * or the object is a MultiPolygon, MultiLineString or MultiPoint and must
     * be handled differently.
     *
     * @param listener Listener providing the onFeatureClick method to call.
     */
public void setOnFeatureClickListener(final OnFeatureClickListener listener) {
    GoogleMap map = getMap();
    map.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {

        @Override
        public void onPolygonClick(Polygon polygon) {
            if (getFeature(polygon) != null) {
                listener.onFeatureClick(getFeature(polygon));
            } else if (getContainerFeature(polygon) != null) {
                listener.onFeatureClick(getContainerFeature(polygon));
            } else {
                listener.onFeatureClick(getFeature(multiObjectHandler(polygon)));
            }
        }
    });
    map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            if (getFeature(marker) != null) {
                listener.onFeatureClick(getFeature(marker));
            } else if (getContainerFeature(marker) != null) {
                listener.onFeatureClick(getContainerFeature(marker));
            } else {
                listener.onFeatureClick(getFeature(multiObjectHandler(marker)));
            }
            return false;
        }
    });
    map.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {

        @Override
        public void onPolylineClick(Polyline polyline) {
            if (getFeature(polyline) != null) {
                listener.onFeatureClick(getFeature(polyline));
            } else if (getContainerFeature(polyline) != null) {
                listener.onFeatureClick(getContainerFeature(polyline));
            } else {
                listener.onFeatureClick(getFeature(multiObjectHandler(polyline)));
            }
        }
    });
}
Also used : GoogleMap(com.google.android.gms.maps.GoogleMap) Polyline(com.google.android.gms.maps.model.Polyline) Marker(com.google.android.gms.maps.model.Marker) Polygon(com.google.android.gms.maps.model.Polygon)

Aggregations

GoogleMap (com.google.android.gms.maps.GoogleMap)8 LatLng (com.google.android.gms.maps.model.LatLng)6 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)5 OnMapReadyCallback (com.google.android.gms.maps.OnMapReadyCallback)3 Bitmap (android.graphics.Bitmap)1 Location (android.location.Location)1 View (android.view.View)1 MapFragment (com.google.android.gms.maps.MapFragment)1 MapView (com.google.android.gms.maps.MapView)1 SupportMapFragment (com.google.android.gms.maps.SupportMapFragment)1 Marker (com.google.android.gms.maps.model.Marker)1 Polygon (com.google.android.gms.maps.model.Polygon)1 PolygonOptions (com.google.android.gms.maps.model.PolygonOptions)1 Polyline (com.google.android.gms.maps.model.Polyline)1 PolylineOptions (com.google.android.gms.maps.model.PolylineOptions)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)1