How to implement lazy loading for markers on Google Maps in Android.

If your objects which you want to show on the Google Maps in Android have different markers. You need to use lazy loading for markers.

How to do it? It’s very easy. Just use AsyncTask . 

Below you can download source code of Android project.

When you start application you can see Google Maps with red default markers. When custom marker loaded the custom marker will replace default marker and update map overlay.

To see map you need specify your own Google Maps API Key in MapView  (see main.xml file)

< ?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<com .google.android.maps.MapView 
		android:id="@+id/mapView" 
		android:layout_width="fill_parent" 
		android:layout_height="fill_parent"
		android:clickable="true" 
		android:apiKey="YOUR_API_KEY"></com>
</linearlayout>

Other info you can see in the code. It is simple to understand. Please, add the questions in comments.

Here code of the AsyncTask class

(more…)