Search in sources :

Example 1 with LatLng

use of com.google.android.libraries.maps.model.LatLng in project google-maps by capacitor-community.

the class CapacitorGoogleMaps method addMarker.

@PluginMethod()
public void addMarker(final PluginCall call) {
    final Double latitude = call.getDouble("latitude", 0d);
    final Double longitude = call.getDouble("longitude", 0d);
    final Float opacity = call.getFloat("opacity", 1.0f);
    final String title = call.getString("title", "");
    final String snippet = call.getString("snippet", "");
    final Boolean isFlat = call.getBoolean("isFlat", true);
    final JSObject metadata = call.getObject("metadata");
    final String url = call.getString("iconUrl", "");
    final Boolean draggable = call.getBoolean("draggable", false);
    if (googleMap == null) {
        call.reject("Map is not ready");
        return;
    }
    Bitmap imageBitmap = getBitmapFromURL(url);
    getBridge().getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            LatLng latLng = new LatLng(latitude, longitude);
            MarkerOptions markerOptions = new MarkerOptions();
            markerOptions.position(latLng);
            markerOptions.alpha(opacity);
            markerOptions.title(title);
            markerOptions.snippet(snippet);
            markerOptions.flat(isFlat);
            markerOptions.draggable(draggable);
            if (imageBitmap != null) {
                markerOptions.icon(BitmapDescriptorFactory.fromBitmap(imageBitmap));
            }
            Marker marker = googleMap.addMarker(markerOptions);
            // set metadata to marker
            marker.setTag(metadata);
            // get auto-generated id of the just added marker,
            // put this marker into a hashmap with the corresponding id,
            // so we can retrieve the marker by id later on
            mHashMap.put(marker.getId(), marker);
            // initialize JSObject to return when resolving this call
            JSObject result = new JSObject();
            JSObject markerResult = new JSObject();
            // get marker specific values
            markerResult.put("id", marker.getId());
            result.put("marker", markerResult);
            call.resolve(result);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) JSObject(com.getcapacitor.JSObject) LatLng(com.google.android.libraries.maps.model.LatLng) Marker(com.google.android.libraries.maps.model.Marker) PluginMethod(com.getcapacitor.PluginMethod)

Example 2 with LatLng

use of com.google.android.libraries.maps.model.LatLng in project google-maps by capacitor-community.

the class CapacitorGoogleMaps method addPolyline.

@PluginMethod()
public void addPolyline(final PluginCall call) {
    final JSArray points = call.getArray("points", new JSArray());
    getBridge().executeOnMainThread(new Runnable() {

        @Override
        public void run() {
            PolylineOptions polylineOptions = new PolylineOptions();
            for (int i = 0; i < points.length(); i++) {
                try {
                    JSONObject point = points.getJSONObject(i);
                    LatLng latLng = new LatLng(point.getDouble("latitude"), point.getDouble("longitude"));
                    polylineOptions.add(latLng);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            googleMap.addPolyline(polylineOptions);
            call.resolve();
        }
    });
}
Also used : JSONObject(org.json.JSONObject) JSArray(com.getcapacitor.JSArray) JSONException(org.json.JSONException) LatLng(com.google.android.libraries.maps.model.LatLng) PolylineOptions(com.google.android.libraries.maps.model.PolylineOptions) PluginMethod(com.getcapacitor.PluginMethod)

Example 3 with LatLng

use of com.google.android.libraries.maps.model.LatLng in project google-maps by capacitor-community.

the class CapacitorGoogleMaps method create.

@PluginMethod()
public void create(PluginCall call) {
    final Integer width = call.getInt("width", DEFAULT_WIDTH);
    final Integer height = call.getInt("height", DEFAULT_HEIGHT);
    final Integer x = call.getInt("x", 0);
    final Integer y = call.getInt("y", 0);
    final Float zoom = call.getFloat("zoom", DEFAULT_ZOOM);
    final Double latitude = call.getDouble("latitude");
    final Double longitude = call.getDouble("longitude");
    final boolean liteMode = call.getBoolean("enabled", false);
    final CapacitorGoogleMaps ctx = this;
    getBridge().getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            LatLng latLng = new LatLng(latitude, longitude);
            CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(zoom).build();
            GoogleMapOptions googleMapOptions = new GoogleMapOptions();
            googleMapOptions.camera(cameraPosition);
            googleMapOptions.liteMode(liteMode);
            if (mapViewParentId != null) {
                View viewToRemove = ((ViewGroup) getBridge().getWebView().getParent()).findViewById(mapViewParentId);
                if (viewToRemove != null) {
                    ((ViewGroup) getBridge().getWebView().getParent()).removeViewInLayout(viewToRemove);
                }
            }
            FrameLayout mapViewParent = new FrameLayout(getBridge().getContext());
            mapViewParentId = View.generateViewId();
            mapViewParent.setId(mapViewParentId);
            mapView = new MapView(getBridge().getContext(), googleMapOptions);
            FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(getScaledPixels(width), getScaledPixels(height));
            lp.topMargin = getScaledPixels(y);
            lp.leftMargin = getScaledPixels(x);
            mapView.setLayoutParams(lp);
            mapViewParent.addView(mapView);
            ((ViewGroup) getBridge().getWebView().getParent()).addView(mapViewParent);
            mapView.onCreate(null);
            mapView.onStart();
            mapView.getMapAsync(ctx);
        }
    });
    call.resolve();
}
Also used : View(android.view.View) MapView(com.google.android.libraries.maps.MapView) CameraPosition(com.google.android.libraries.maps.model.CameraPosition) GoogleMapOptions(com.google.android.libraries.maps.GoogleMapOptions) FrameLayout(android.widget.FrameLayout) MapView(com.google.android.libraries.maps.MapView) LatLng(com.google.android.libraries.maps.model.LatLng) PluginMethod(com.getcapacitor.PluginMethod)

Example 4 with LatLng

use of com.google.android.libraries.maps.model.LatLng in project android-places-demos by googlemaps.

the class AutocompleteTestActivity method getOrigin.

@Nullable
private LatLng getOrigin() {
    String originStr = ((TextView) findViewById(R.id.autocomplete_location_origin)).getText().toString();
    if (TextUtils.isEmpty(originStr)) {
        return null;
    }
    LatLng origin = StringUtil.convertToLatLng(originStr);
    if (origin == null) {
        showErrorAlert(R.string.error_alert_message_invalid_origin);
        return null;
    }
    return origin;
}
Also used : LatLng(com.google.android.libraries.maps.model.LatLng) Nullable(androidx.annotation.Nullable)

Example 5 with LatLng

use of com.google.android.libraries.maps.model.LatLng in project android-maps-utils by googlemaps.

the class HeatmapsDemoActivity method startDemo.

@Override
protected void startDemo(boolean isRestore) {
    if (!isRestore) {
        getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-25, 143), 4));
    }
    // Set up the spinner/dropdown list
    Spinner spinner = findViewById(R.id.spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.heatmaps_datasets_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new SpinnerActivity());
    try {
        mLists.put(getString(R.string.police_stations), new DataSet(readItems(R.raw.police), getString(R.string.police_stations_url)));
        mLists.put(getString(R.string.medicare), new DataSet(readItems(R.raw.medicare), getString(R.string.medicare_url)));
    } catch (JSONException e) {
        Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
    }
// Make the handler deal with the map
// Input: list of WeightedLatLngs, minimum and maximum zoom levels to calculate custom
// intensity from, and the map to draw the heatmap on
// radius, gradient and opacity not specified, so default are used
}
Also used : Spinner(android.widget.Spinner) JSONException(org.json.JSONException) LatLng(com.google.android.libraries.maps.model.LatLng)

Aggregations

LatLng (com.google.android.libraries.maps.model.LatLng)31 JSONException (org.json.JSONException)8 MarkerOptions (com.google.android.libraries.maps.model.MarkerOptions)7 PluginMethod (com.getcapacitor.PluginMethod)5 PolylineOptions (com.google.android.libraries.maps.model.PolylineOptions)5 MyItem (com.google.maps.android.utils.demo.model.MyItem)5 InputStream (java.io.InputStream)5 JSONObject (org.json.JSONObject)5 PolygonOptions (com.google.android.libraries.maps.model.PolygonOptions)4 Nullable (androidx.annotation.Nullable)3 GoogleMap (com.google.android.libraries.maps.GoogleMap)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 JSONArray (org.json.JSONArray)3 DisplayMetrics (android.util.DisplayMetrics)2 Log (android.util.Log)2 View (android.view.View)2 CircleOptions (com.google.android.libraries.maps.model.CircleOptions)2 LatLngBounds (com.google.android.libraries.maps.model.LatLngBounds)2 Marker (com.google.android.libraries.maps.model.Marker)2