I am adding a large amount of GeoJSON data into Mapbox in an Android app. This makes scrolling through the map very slow on higher zoom levels. For this reason I would like to change the input data based on the current zoom level. I looked for a function like getCurrentZoomlevel(), but all I could find was a getMaxZoomLevel() function in the MapView class and this only gives my the maximum possible zoom level. Is there a function that I can call which gives me the current zoom level?
For this solution to work, I would also need to remove and add certain polygons dynamically based on the zoom level. Is it possible to remove polygons without reloading the entire map?
Starting with 4.0.0 of the Mapbox Android SDK, interaction with the map happens using the MapboxMap object, not the MapView. It sounds like you are trying to add a zoom listener which doesn't exist but a onCameraChangeListener does and from that you can check the zoom level.
mapboxMap.setOnCameraChangeListener(new MapboxMap.OnCameraChangeListener() {
#Override
public void onCameraChange(CameraPosition position) {
...
if (position.zoom < 12) {
...
}
}
});
If your GeoJSON file is large and you are trying to draw polygons/polylines you might want to have a look at the Style API we will be introducing in 4.2.0. It allows you to add geojson layers and style them. If you are interested I'd recommend taking a look at the examples found in the Mapbox Android Demo App. This Github issue shows off a bunch of the examples I added.
EDIT: forgot to mention to remove polygons or polylines from the map you have a few options. Either use mapboxMap.removeAnnotations(); to remove all annotations from the map or mapboxMap.removePolygon(); to remove a polygon for example. removePolygon takes in a Polygon object which you'll need to assign when adding the polygon to the map:
Polygon polygon = map.addPolygon(new PolygonOptions()
.addAll(<List of points making up polygon>)
.setFillColor(color));
Related
Hao, stackoverflow!
I'm using Android Maps Utils to cluster markers, it's a little bit tricky, but generally ok.
Map Utils has some default value, on which zoom level it splits one cluster to several clusters or markers. I just need to do it earlier i.e. i need to start split items on bigger zoom level rather then default value.
I think it's not about shoudRenderAsCluster(cluster), cause this callback called already with splitted clusters after this default zoom level.
I've tried GridBasedAlgorithm (really strange behavior when zooming out) and NonHierarchicalDistanceBasedAlgorithm (it seems default).
Thanks!
I have been searching in the documentation and throughout google. I would like to know if it is possible to place an image over the map the api comes from to use something else as a visual but with the maps gps functionality. Does anyone know if this is possible?
You can use two types of Overlays:
TileOverlays (reference)
A TileOverlay defines a set of images that are added on top of the base map tiles. You can also use tile overlays to add extra features to the map by providing transparent tile images. You need to provide the tiles for each zoom level that you want to support. If you have enough tiles at multiple zoom levels, you can supplement Google's map data for the entire map.
GroundOverlay (reference)
A ground overlay is an image that is fixed to a map. Unlike markers, ground overlays are oriented against the Earth's surface rather than the screen, so rotating, tilting or zooming the map will change the orientation of the image. Ground overlays are useful when you wish to fix a single image at one area on the map. If you want to add extensive imagery that covers a large portion of the map, you should consider a Tile overlay.
I am new to Skobbler and would like to add POIs to my map. However, I do not want them appearing at every zoom level, but rather at a specific margin of levels. I've seen that this is possible for Annotations via the setMininumZoomLevel method and was wondering if there is anything similar to this for the customPOI's. TIA
A custom POI should be an annotation.
The POIs that you see on the map are OSM POIs - if you want to modify the visibility of those POIs, you will need to change the map style.
See this other thread for more context.
I have a MapView (provided by Google Maps Android API v2) and what I'm trying to achieve should be simple enough, which is simply to draw a curved Polyline.
To be specific, I have an array of LatLngs and rather than having them joined at sharp angles, I want to have the route rounded off nicely, so that the line through the points follows a curve rather than straight lines and sharp angles.
Now, this used to be possible in the old Google Maps API by creating a custom Overlay, overriding draw(), and then manually drawing onto the map (e.g. with a custom Paint and Path with the desired settings).
Unfortunately it seems that in v2, Google have removed the Overlay class and moved to higher-level abstractions which no longer provide access to the draw() method. PolylineOptions is fairly basic and doesn't provide any option to draw a curved line.
Is there any way to override draw() or use other features of Google Maps API v2 in order to draw a curved Polyline?
There are a few questions already on SO which cover this issue, however there isn't really a satisfactory answer as yet:
Custom Overlays in Google Maps API v2
Overrinding draw() in customized MapView in Google Maps Android API v2
I'm sure there must be a way to do custom drawing on Google Maps v2, and whilst creating a custom overlay View and drawing onto that once the coordinates are synced up with the map is an option, it will quickly get extremely complicated when dealing with scaling and panning the map, so it's something I want to avoid if at all possible.
I have developed an abstract class CanvasTileProvider() where you just have to override the onDraw method, in order to perform your drawing as usual into a Canvas. A TileProjection object, which is passed into the onDraw method in addition, helps you to do the back and forth calculation between LatLng and points on the Canvas.
The only limitation is, that tiles are usually loaded only once. So this way of drawing into the map is suitable for shapes which do not frequently change. Thus it may not be suitable if your array of LatLng objects is continuously changing (e.g. because it shows the current movement of the device).
You can find the CanvasTileProvider class in the answer to this SO question
I want to build an app that uses GPS data and a building map I provide to show the user where in the building on the map they are. This will be done in a specific building that i already know gets GPS and cell service.
At first I thought the easiest way to do this was to see if I could use Google maps to plot the users location and then just "overlay" my custom building map on top of the Google map so that I wouldnt have to deal with any of the gps information or the complexities of the mapping I would just have to scale my "overlay" to fit properly on top of the Google map so that the user was shown in the correct room in a building. I'm wondering if anyone can provide me any information on how to do this or if there is an easier way to accomplish my map. Any information at all is helpful!
You want...
Google Map View
...and more specifically you will probably want to read the subsection appropriately titled: "Part 2: Adding Overlay Items"
EDIT: Whoops! Nevermind! I misread your question... that is only if you want to overlay an item on the map. Sorry...
There is no possibility to use closer zoom level than that you can see on standard GMap i.e. in browser. Other problem is that google uses GeoPoint class based on cardinal microdegrees to draw overlays, and it's accuracy is to low.
You can look on jGarminImg - it's java library - unfortunately written for using with swing, but it should be relatively easy to make it work with android. On the other hand - you have to make your own map.
You can use standard overlays, or you can make your map in kml format and use this example to display it.
You may be able to achieve this with a custom view that displays your building plan and knows the precise co-ordinates of each corner of the building.
When you receive your location updates you can add a marker to your custom view by translating the real world position into a position in the image using something along the lines of:
pseudocode:
markerX = realWorldX - mapStartX;
markerY = realWorldY - mapStartY;
if( isOnMap( markerX, markerY ) )
{
drawMarker( markerX, markerY );
}
Yes you can overlay bitmap images on top of the Google MapView.
All you have to do is subclass the Overlay class, override the draw method, and draw on the canvas. You have to provide a rectangle of GeoPoints (probably the top left and the bottom right corners) to anchor the building bitmap on top of the MapView. You use mapView.getProjection() to translate the latitude and longitude into xy coordinates on the canvas.
I assume drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) will be useful here. Bear in mind that src and paint can be null. If the GeoPoints you used are accurate, the bitmap will adjust automatically to pans and zooms, although it might get pixelated if the user zooms in too much.
edit: I am not so confident that Google Maps will have your building stays at the exact same GeoPoints in different zoom levels, so you might have to adjust those values for different zoom levels
If you need only the map of the building, it should not be too difficult to plot the location on an image without using Google Maps, provided that you can determine your location as coordinates inside the building.
You need to know two coordinates: north-west and south-east corners of the building map you are using. When you get GPS location updates, the correct location on the map image can be easily calculated based on these corner coordinates.
I would do it like this,
Place a marker on the google map to indicate the position of the building
Drilling down on the building would load your building map as a custom view. Plot the user location on the custom view
I think trying to overlay your building map on a google map while possible will be more complex to code than doing it via a custom view.
Also overlaying the lowest zoom level with your building map is not going to give you enough resolution unless you have a thumping big building. Whole blocks are pretty small
One issue you have probably already considered is the device will revert to cell tower and wifi for it's location when inside the building giving you a less accurate location fix.