Search in sources :

Example 6 with LatLng

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

the class HeatmapsDemoActivity method readItems.

// Datasets from http://data.gov.au
private ArrayList<LatLng> readItems(int resource) throws JSONException {
    ArrayList<LatLng> list = new ArrayList<>();
    InputStream inputStream = getResources().openRawResource(resource);
    String json = new Scanner(inputStream).useDelimiter("\\A").next();
    JSONArray array = new JSONArray(json);
    for (int i = 0; i < array.length(); i++) {
        JSONObject object = array.getJSONObject(i);
        double lat = object.getDouble("lat");
        double lng = object.getDouble("lng");
        list.add(new LatLng(lat, lng));
    }
    return list;
}
Also used : Scanner(java.util.Scanner) JSONObject(org.json.JSONObject) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) LatLng(com.google.android.libraries.maps.model.LatLng)

Example 7 with LatLng

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

the class IconGeneratorDemoActivity method startDemo.

@Override
protected void startDemo(boolean isRestore) {
    if (!isRestore) {
        getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8696, 151.2094), 10));
    }
    IconGenerator iconFactory = new IconGenerator(this);
    addIcon(iconFactory, "Default", new LatLng(-33.8696, 151.2094));
    iconFactory.setColor(Color.CYAN);
    addIcon(iconFactory, "Custom color", new LatLng(-33.9360, 151.2070));
    iconFactory.setRotation(90);
    iconFactory.setStyle(IconGenerator.STYLE_RED);
    addIcon(iconFactory, "Rotated 90 degrees", new LatLng(-33.8858, 151.096));
    iconFactory.setContentRotation(-90);
    iconFactory.setStyle(IconGenerator.STYLE_PURPLE);
    addIcon(iconFactory, "Rotate=90, ContentRotate=-90", new LatLng(-33.9992, 151.098));
    iconFactory.setRotation(0);
    iconFactory.setContentRotation(90);
    iconFactory.setStyle(IconGenerator.STYLE_GREEN);
    addIcon(iconFactory, "ContentRotate=90", new LatLng(-33.7677, 151.244));
    iconFactory.setRotation(0);
    iconFactory.setContentRotation(0);
    iconFactory.setStyle(IconGenerator.STYLE_ORANGE);
    addIcon(iconFactory, makeCharSequence(), new LatLng(-33.77720, 151.12412));
}
Also used : LatLng(com.google.android.libraries.maps.model.LatLng) IconGenerator(com.google.maps.android.ui.IconGenerator)

Example 8 with LatLng

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

the class VisibleClusteringDemoActivity method startDemo.

@Override
protected void startDemo(boolean isRestore) {
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int widthDp = (int) (metrics.widthPixels / metrics.density);
    int heightDp = (int) (metrics.heightPixels / metrics.density);
    if (!isRestore) {
        getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(51.503186, -0.126446), 10));
    }
    mClusterManager = new ClusterManager<>(this, getMap());
    mClusterManager.setAlgorithm(new NonHierarchicalViewBasedAlgorithm<>(widthDp, heightDp));
    getMap().setOnCameraIdleListener(mClusterManager);
    try {
        readItems();
    } catch (JSONException e) {
        Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
    }
}
Also used : JSONException(org.json.JSONException) LatLng(com.google.android.libraries.maps.model.LatLng) DisplayMetrics(android.util.DisplayMetrics)

Example 9 with LatLng

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

the class ZoomClusteringDemoActivity method startDemo.

@Override
protected void startDemo(boolean isRestore) {
    if (!isRestore) {
        getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(18.528146, 73.797726), 9.5f));
    }
    ClusterManager<MyItem> clusterManager = new ClusterManager<>(this, getMap());
    getMap().setOnCameraIdleListener(clusterManager);
    // Initialize renderer
    ZoomBasedRenderer renderer = new ZoomBasedRenderer(this, getMap(), clusterManager);
    clusterManager.setRenderer(renderer);
    // Set click listeners
    clusterManager.setOnClusterClickListener(this);
    clusterManager.setOnClusterInfoWindowClickListener(this);
    clusterManager.setOnClusterItemClickListener(this);
    clusterManager.setOnClusterItemInfoWindowClickListener(this);
    String snippet = "This item wouldn't have changed to a marker if we didn't override shouldRenderAsCluster() AND shouldRender()";
    // Add items
    clusterManager.addItem(new MyItem(18.528146, 73.797726, "Loc1", snippet));
    clusterManager.addItem(new MyItem(18.545723, 73.917202, "Loc2", snippet));
}
Also used : LatLng(com.google.android.libraries.maps.model.LatLng) ClusterManager(com.google.maps.android.clustering.ClusterManager) MyItem(com.google.maps.android.utils.demo.model.MyItem)

Example 10 with LatLng

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

the class DistanceDemoActivity method startDemo.

@Override
protected void startDemo(boolean isRestore) {
    mTextView = findViewById(R.id.textView);
    if (!isRestore) {
        getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.8256, 151.2395), 10));
    }
    getMap().setOnMarkerDragListener(this);
    mMarkerA = getMap().addMarker(new MarkerOptions().position(new LatLng(-33.9046, 151.155)).draggable(true));
    mMarkerB = getMap().addMarker(new MarkerOptions().position(new LatLng(-33.8291, 151.248)).draggable(true));
    mPolyline = getMap().addPolyline(new PolylineOptions().geodesic(true));
    Toast.makeText(this, "Drag the markers!", Toast.LENGTH_LONG).show();
    showDistance();
}
Also used : MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) LatLng(com.google.android.libraries.maps.model.LatLng) PolylineOptions(com.google.android.libraries.maps.model.PolylineOptions)

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