Skip to main content

Put Multiple Marker on Map? It's So Damm Easy..

If you want to put multiple marker on google map, then just follow some snip of code below and enjoy it.

// Initialize variables
 private GoogleMap mMap;  
 private HashMap<Marker, Integer> mHashMap = new HashMap<Marker, Integer>();  
 private ArrayList<My_Custom_Model_Class> myList = new ArrayList<My_Custom_Model_Class>();  

// Add Multiple marker on Map
 for (int i = 0; i < myList.size(); i++) {  
   double latitude = myList.getLatitude();  
   double longitude = myList.getLongitude();  
   Marker marker = mMap.addMarker(new MarkerOptions().position(new LatLng(latitude,longitude))).title(myList.getTitle())  
                     .icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon));  
   mHashMap.put(marker, i);  
 }   

// If you want to get particular marker click
 @Override  
 public boolean onMarkerClick(Marker marker) {   
   int pos = mHashMap.get(marker);  
   Log.i("Position of arraylist", pos+"");  
 } 

Comments

Popular posts from this blog

Error: Retrieving parent for item: No resource found that matches the given name after upgrading to AppCompat v23

My project is going on easily but suddenly what I found below bugs when developing an app. I know it's minor bug but it may be useful to anyone. Here is the error: Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'. Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'. Solution: This happens because after updates your android studio uses API 23 by default. 1) First check that your compile SDK version must match the support library's major version. If you are using version 23 of the support library, you need to compile against version 23 of the Android SDK. Alternatively you can continue compiling against version 22 of the Android SDK by switching to the latest support library v22.   2) Go to your project structure -> Properties -> and change Build tool version to...

Be aware while Posting photo from a native ShareDialog in Facebook android SDK

Add the content provider to your manifest. <provider  android:name="com.facebook.NativeAppCallContentProvider" android:authorities="com.facebook.app.NativeAppCallContentProvider{Facebook-App-Id}" android:exported="true" /> Make sure exported=true (as above) Example: <provider android:name="com.facebook.NativeAppCallContentProvider" android:authorities="com.facebook.app.NativeAppCallContentProvider123456" android:exported="true" />

Android: Google Map V2

1. Downloading Google Play Services Google made new Maps V2 API as a part of Google Play Services SDK. So before we start developing maps we need to download google play services from SDK manger. You can open SDK manager either from Eclipse or from android sdk folder. Open Eclipse ⇒ Windows ⇒ Android SDK Manager and check whether you have already downloaded Google Play Services or not under Extras section. If not select play services and install the package.  2. Importing Google Play Services into Eclipse After downloading play services we need to import it to Eclipse which will be used as a library for our maps project. 1 . In Eclipse goto File ⇒ Import ⇒ Android ⇒ Existing Android Code Into Workspace 2 . Click on Browse and select Google Play Services project from your android sdk folder. You can locate play services library project from android-sdk-windows\extras\google\google_play_services\libproject\google-play-services_lib 3 . Importantly while importin...