Scale the image for a map overlay - google maps - android

I followed the tutorial for map overlays that Google offers (http://developer.android.com/resources/tutorials/views/hello-mapview.html) and it works fine, except the image for the overlay doesn't scale when you zoom in and out. I have Maps zoomed in on a city, and I want to put markets on several of the buildings, but the overlay image doesn't scale when it zooms in. Is there a way to have the overlay image scale up and down as users zoom in and out?
I have seen the answer where they used vector circles as the points on the map. That wont work for me, because I need to use custom images as the point on my map.
If you want to see my code, I can post it, but it is the exact the same as the example, except for some variable name changes.

Related

Android Is it possible to change the appearance of the map in the google maps API

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.

How to use own custom imagery instead of google map in Android app

I have developed an app in android where I am using Google Map for capturing location. I have a large satellite image ( greater than 500 mb ), this image is geo-coded. We need to display this as one of the layers in the map like google map has a choice for satellite imagery. How can it be done.
Thank you in advance.
To add custom imaginery to your map you can use TileOverlay:
From the documentation of TileOverlay
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.
Tile overlays are useful when you want to add extensive imagery to the map, typically covering large geographical areas. In contrast, ground overlays are useful when you wish to fix a single image at one area on the map.
To use TileOverlay you need to implement a TileProvider that returns the correct Tile object for each tile requested by the map.
Take into account that your data (your images) need to be georeferenced to return the correct tiles to be drawn on the map.
Once your data is displayed you may want to do map.setMapType(GoogleMap.MAP_TYPE_NONE); to stop asking for Google tiles.
Update based on the comments:
As you say that you want to automate the tiling for different image formats, you will need to implement a TileProvider for each of the image formats that you want to be able to load.
To return the correct Tile you will need to transform between the tile x, y, and zoom (the parameters of the public Tile getTile(int x, int y, int zoom) function of the TileProvider interface) and the coordinates (and pixels) of you georeferenced image. You can take a look at http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/ to learn more about the tiling system.
Also, if the image's srid not WGS84 you will need to geotransform your data.
Take into account that if your image is big and you are showing a large area you may find OutOfMemory errors, and you may want to take a look at Loading Large Bitmaps Efficiently to load a scaled down version of your image to be returned as the tile.

Android Google map with inset overview when zoomed in

I am developing an android application using Google maps with clustering of markers. The application works fine however once you zoom into a specific area and all the clusters expand to individual markers I would like to also show a small view that represents the entire map, where you are, and where all the markers are, to enable the user to navigate round the map while zoomed in. Ive Googled and searched SO, but not found anything. Is there any "off the shelf" solution? Or am I going to have to code this all myself? The type of solution I am looking for is the type of small window that many games use to show an overview of where the player is and all the points of interest are within the current level.
I haven't seen any "off the shelf" solutions, but here is what I would do here:
1) Create an additional fragment of the map. Place it in one of corners like games do
2) Here is where all the magic should happen. You need to synchronize these 2 maps. Map's Projection lets you to translate geo coordinates into XY coordinates within the view. That's being said you can get lat/lng of your top-left and bottom-right corners on the main map and translate these 2 corners into top-left and bottom-right XY coordinates of the mini-map's view. Now, when you have XY coordinates, the only thing you need to do - is to draw a rect on top of the mini map.
There is even easier and more native solution - since you have top-left and bottom-right lat/lng coordinates - you can draw a set of polylines on a minimap to get a rect. But in this case it will be hard to move it around (with your finger) in case you want to change current main map location using mini-map

Smooth zoom in Android MapView?

I have a MapView with one overlay. Overlay renders tile based map over the MapView. I use MapView.getZoomLevel() to retrieve current zoom level for Google map and for my tiles. Everything works just perfect, but only if user don't zoom the map using multitouch gestures. As I understand, the MapView control don't render actual tiles during zooming process, but just show stretched screen content. So, the question is - How to get this scale ratio which I can use to render my tiles exactly in same way as Google do?
Thank You!
Although the method MapView.getZoomLevel() isn't aligned with zoom changes animation and multitouche, the methods MapView.getProjection().fromPixels() and MapView.getProjection().fromPixels() are.
So you have several option to adress the issue. From the methos above, you can find the direct (x,y) coordinates (and size) where to render the tiles or you can find the zoom ration using something like:
int lonSpan = projection.fromPixels(0,mapView.getHeight()/2).getLongitudeE6() -
projection.fromPixels(mapView.getWidth(),mapView.getHeight()/2).getLongitudeE6();
which gives you the longitude span at map vertical center. Then, you divide the value after zoom starts from the value before zoom starts.
Regards.

Android custom GPS map application

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.

Categories

Resources