Is it possible to draw a custom region using the Android Google maps API?
The currently available tiles in google maps are missing some information and I was wondering if it is possible to draw custom shapes on top of the Map using overlays?
Also do overlays occupy an entire layer on top of the existing map, or do they only occupy the region which is encompassed in the draw method?
I want only the custom drawn region(if possible) to be interactive to user touches and hence need only the drawn region to respond in a certain manner to user touches/gestures.
Help appreciated.
Related
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 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
Are there any restrictions as to what types of custom Views can be used in an Android maps v2 marker InfoWindow? While I have been able to add many types of views, I have not been able to add a GLSurfaceView.
Android maps v2 allows for custom views in a marker's InfoWindow. I understand that the GLSurfaceView will not be interactive in any way, as the Android dev site states:
The info window that is drawn is not a live view. The view is rendered
as an image (using View.draw(Canvas)) at the time it is returned
but I thought that it would at least capture the GLSurfaceView as an image as it exists right when InfoWindow.getInfoContents() is called, but the InfoWindow is only black where the GLSurfaceView would be.
Any ideas?
I have developing an Android application, and I have moved from Google Maps for Android API v1 to v2.
With deprecated version 1 I created an Overlay for drawing some colored shapes (delimiting zones) and info text over my map, but now I have been viewing API v2 and cannot do the same.
I have trying to use Polygon property, but it doesn't fill with any colour, maybe because my shapes cannot be drawing in counterclockwise due to the pattern of them, for example a shape with 'U' pattern. Also, I don't know either how to put a text (no marker, just text) over the map.
Thanks in advance.
still don't know how to put a text in the map
Create a Bitmap containing your text, and use a GroundOverlay, or possibly a TileOverlay.
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.