Forums General How to show an image overlay on the map in an android app.

This topic contains 1 replies, has 2 voice, and was last updated by Florence Gayhart 1 week, 1 day ago
  • Abhay Singh

    Hi,
    The HERE Maps API for JavaScript provides an easy means of overlaying the region on the map with the bitmap image by using the H.map.Overlay object.
    Now I want to implement similar functionality in an android app to overlay an image onto the
    map by providing the bounding box coordinates and an image URL. Can someone guide me how to implement this?

    Florence Gayhart

    Hello,

    Certainly! To overlay an image on a Google Map in an Android app using bounding box coordinates and an image URL, you can follow these steps:

    Load the Image from URL:
    Use a library like Picasso to load the image from the provided URL. This library simplifies image loading and caching from the internet.
    In your AsyncTask, fetch the image from the URL and create a BitmapDescriptor object1.
    Create a GroundOverlay:
    Once you have the BitmapDescriptor, create a GroundOverlayOptions object.
    Set the image using .image(bitmapDescriptor).
    Specify the position (latitude and longitude) where you want to overlay the image using .position(point1, 500f) (adjust the position as needed).
    Set transparency with .transparency(0.5f) (adjust transparency as desired).
    Add the GroundOverlay to the Map:
    Finally, add the GroundOverlayOptions to your Google Map using googleMap.addGroundOverlay(groundOverlay).
    Here’s a sample code snippet:
    public class AddGroundOverlay extends AsyncTask<String, Integer, BitmapDescriptor> {
    BitmapDescriptor bitmapDescriptor;

    @Override
    protected BitmapDescriptor doInBackground(String… url) {
    String myUrl = url[0];
    try {
    bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(Picasso.with(getActivity()).load(myUrl).get());
    } catch (IOException e) {
    e.printStackTrace();
    }
    return bitmapDescriptor;
    }

    @Override
    protected void onPostExecute(BitmapDescriptor icon) {
    try {
    GroundOverlayOptions groundOverlay = new GroundOverlayOptions()
    .image(icon)
    .position(point1, 500f) // Adjust position
    .transparency(0.5f); // Adjust transparency
    googleMap.addGroundOverlay(groundOverlay);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    Hope this work for you.
    Best regards,
    Florence Gayhart
    https://www.my-loweslife.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.