Gonzalo Diaz Harcha
Gonzalo Diaz Harcha

Reputation: 21

Image in Google Maps (Android)

I have the google map in my app, but this map have a blank part in the location i want (a map of a factory for example). Then i want to put a customize map in that place, so when the user is navigating near the factory, appear my map, not blank part.

Im looking for any solution, thanks.

Upvotes: 1

Views: 2151

Answers (2)

Droid Chris
Droid Chris

Reputation: 3783

You can simply place the drawable as a marker in your ovelay. That will cause the overlay to be bounded to the set position in the map based on the GeoPoint.

To do this, change the overlay's marker to the drawable you have and then add the item to the overlay with this drawable.

            private void addOverlayItem(GeoPoint point,int radius){
    //create circle
    Circle circle = new Circle(Color.RED,radius);

    //manipulate overlay 
    OverlayItem overlayitem = new OverlayItem(point,null,null);
    overlayitem.setMarker(circle);

    //add circle to overlay
    boundaryitemizedOverlay.addOverlay(overlayitem);
}

Upvotes: 0

John J Smith
John J Smith

Reputation: 11931

Get an image (png or bitmap) of your factory and add it to a map overlay. The tricky part will be redrawing the image at the correct point on the screen when the user scrolls the map and/or zooms in or out. If you extend the ItemizedOverlay class you can override the draw() method and redraw your factory image as appropriate to the scale and relative position of the map to the device's screen. There are two approaches I'm aware of. First, you can have one image and then rescale that image using a Matrix transform explained here. Alternatively, you can have several different sized images which you swap out depending on the zoom level - the smaller images being used as you zoom out. Also, you may not want to show an image at all if the user zooms out too far.

@Override
public void draw(Canvas canvas, MapView mapv, boolean shadow)
{       
    int zoom = mapv.getZoomLevel();

    switch(zoom)
    {
        case 19:
            setMarkersForZoomLevel19();
            break;
        case 18:
            setMarkersForZoomLevel18();
            break;
        case 17:
            setMarkersForZoomLevel17();
            break;
        case 16:
            setMarkersForZoomLevel16();
            break;
        default:
            // Hide the markers or remove the overlay from the map view.                
            mapv.getOverlays().clear();
    }       

    area.drawArea(canvas, mapv);

    // Putting this call here rather than at the beginning, ensures that
    // the Overlay items are drawn over the top of canvas stuff e.g. route lines.
    super.draw(canvas, mapv, false);        

}


private void setMarkersForZoomLevel19()
{       
    for (MyOverlayItem item : mOverlays)
    {               
        item.setMarker(areaPointIcon48);            
    }
}

This shows one of the methods for setting the markers to a different-sized icon.

Upvotes: 2

Related Questions