Skip to main content

Map Overlay Demo

After creating your first Google Maps Application,you may wish to add markers to the map to indicate places of interests.That's what you will see  in this article.

Adding markers
First you need to define a new class that extends the ItemizedOverlay class, which can manage a whole set of Overlays(the individual items placed in the map).

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class CustomItemizedOverlay extends ItemizedOverlay{

 private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
 Context mContext;
 
 public CustomItemizedOverlay(Drawable defaultMarker) {
  super(defaultMarker);
  }

 public CustomItemizedOverlay(Drawable defaultMarker,Context context) {
    super(defaultMarker);
    mContext = context;
 }
 public void addOverlay(OverlayItem overlay) {
     mOverlays.add(overlay);
     populate();
 }
 
 @Override
 protected OverlayItem createItem(int i) {  
  return mOverlays.get(i);
 }

 @Override
 public int size() {
  return mOverlays.size();
 }
}

Go back to your main class  MapsActivity .In the following procedure, you'll  create  OverlayItem  and add it to an instance of CustomItemizedOverlay class,then add the CustomItemizedOverlay to the MapView using a GeoPoint  to define its coordinates on the map.
1- First, add an image for the map overlay under res/drawable directory of the project.
2- At the end of your onCreate() method, add 

List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
CustomItemizedOverlay itemizedoverlay = new CustomItemizedOverlay(drawable);


3- Now create an Array of Geopoint that represents the locations of places  you want to show in the map. 

// Define an array containing the mosque overlay items
        
   private OverlayItem [] mosqueItem = {
    new OverlayItem( new GeoPoint(35403398,1054842), "Zitouna Mosque", "Kairouan"),
    new OverlayItem( new GeoPoint(36513315,10194294), "El Abidine Mosque", "El Abidine Mosque")   
        };

4- Add the list of OverlayItem to your collection in the  CustomItemizedOverlay instance.Then add the CustomItemizedOverlay to your MapView.
for(int i=0; i<mosqueitem.length;i++ )
  itemizedoverlay.addOverlay(mosqueitem[i]);                                                                           
mapOverlays.add(itemizedoverlay); 


Your Application looks like the following one :




Comments

Post a Comment

Popular posts from this blog

What You Must Know Before Establishing a Recovery Plan ?

In today's rapidly evolving digital landscape, organizations are increasingly adopting the zero trust model, primarily due to the expanding attack surface that leaves critical systems and data exposed. This shift is also fueled by the heightened sophistication of cyber-attacks, which have become more complex and harder to detect, surpassing traditional security measures. Additionally, the existing operating models within organizations are often inconsistent, typically characterized by distributed and siloed environments.    This fragmentation creates vulnerabilities and makes it challenging to implement uniform security protocols. The zero trust model addresses these challenges by assuming that threats exist both inside and outside the network, necessitating continuous verification of all users and devices. Its adoption represents a proactive stance in the ongoing battle against cyber threats, ensuring a more robust and resilient organizational security posture. The Evolution ...

A comprehensive guide to ransomware distribution in VMware environments

In a virtualized on-premises environment based on VMware, ransomware distribution scenarios can be somewhat unique due to the nature of virtualization technology. However, many of the traditional attack vectors still apply. Here are some ransomware distribution scenarios specific to a VMware-based virtualized environment: Phishing Attacks Targeting Administrators: Administrators with access to the VMware environment might receive phishing emails. If they fall for these and their credentials are compromised, attackers can gain access to the virtualized environment. Exploiting Vulnerabilities in VMware Software: If VMware software or the underlying operating system is not kept up-to-date with security patches, vulnerabilities can be exploited by attackers to deliver ransomware into the virtualized environment. Compromised Remote Management Tools: Tools used for remote management of the virtualized environment, such as vSphere, can be a target. If these tools are compromised, attackers ca...

Edge Computing Demystified Book

After a while I'm back and pleased  to share in this post my first book around Edge computing Technologies. Edge computing has been a very hot and interesting topic nowadays for communication service provider and Enterprise so far. Augmented Reality / Virtual Reality, Smart cities, Healthcare, industrial IoT and many others use cases require a change in the way we operate and host application in the cloud.  IA, Big Data and analytics are often used today to understand the behavior of the customer and even the health of services. Real-time and high throughput demand are the characteristic of the new business services. Edge computing technology promises to resolve different challenges and brings compute, storage and bandwidth close to the data source. I tried in ‘the Edge Computing Demystified’ book to explain Edge computing technology referring to different use cases from communication service provider and enterprise industry. I h...