├── AndroidManifest.xml ├── README.md ├── ic_launcher-web.png ├── java └── com │ └── rogcg │ └── androidgmaps │ ├── MainActivity.java │ └── MyMarker.java └── res ├── drawable-hdpi ├── currentlocation_icon.png ├── ic_launcher.png ├── icon1.png ├── icon2.jpeg ├── icon3.gif ├── icon4.png ├── icon5.gif ├── icon6.png ├── icon7.gif └── icondefault.png ├── drawable-mdpi └── ic_launcher.png ├── drawable-xhdpi └── ic_launcher.png ├── drawable-xxhdpi └── ic_launcher.png ├── layout ├── activity_main.xml └── infowindow_layout.xml ├── menu └── main.xml ├── values-w820dp └── dimens.xml └── values ├── dimens.xml ├── strings.xml └── styles.xml /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Sample code for "Android working with Google Maps V2 and Custom Markers" 2 | ================================= 3 | -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/ic_launcher-web.png -------------------------------------------------------------------------------- /java/com/rogcg/androidgmaps/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.rogcg.androidgmaps; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.ImageView; 7 | import android.widget.TextView; 8 | import android.widget.Toast; 9 | 10 | import com.google.android.gms.maps.GoogleMap; 11 | import com.google.android.gms.maps.MapFragment; 12 | import com.google.android.gms.maps.model.BitmapDescriptorFactory; 13 | import com.google.android.gms.maps.model.LatLng; 14 | import com.google.android.gms.maps.model.Marker; 15 | import com.google.android.gms.maps.model.MarkerOptions; 16 | 17 | import java.util.ArrayList; 18 | import java.util.HashMap; 19 | 20 | public class MainActivity extends Activity 21 | { 22 | private GoogleMap mMap; 23 | private ArrayList mMyMarkersArray = new ArrayList(); 24 | private HashMap mMarkersHashMap; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) 28 | { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_main); 31 | 32 | // Initialize the HashMap for Markers and MyMarker object 33 | mMarkersHashMap = new HashMap(); 34 | 35 | mMyMarkersArray.add(new MyMarker("Brasil", "icon1", Double.parseDouble("-28.5971788"), Double.parseDouble("-52.7309824"))); 36 | mMyMarkersArray.add(new MyMarker("United States", "icon2", Double.parseDouble("33.7266622"), Double.parseDouble("-87.1469829"))); 37 | mMyMarkersArray.add(new MyMarker("Canada", "icon3", Double.parseDouble("51.8917773"), Double.parseDouble("-86.0922954"))); 38 | mMyMarkersArray.add(new MyMarker("England", "icon4", Double.parseDouble("52.4435047"), Double.parseDouble("-3.4199249"))); 39 | mMyMarkersArray.add(new MyMarker("España", "icon5", Double.parseDouble("41.8728262"), Double.parseDouble("-0.2375882"))); 40 | mMyMarkersArray.add(new MyMarker("Portugal", "icon6", Double.parseDouble("40.8316649"), Double.parseDouble("-4.936009"))); 41 | mMyMarkersArray.add(new MyMarker("Deutschland", "icon7", Double.parseDouble("51.1642292"), Double.parseDouble("10.4541194"))); 42 | mMyMarkersArray.add(new MyMarker("Atlantic Ocean", "icondefault", Double.parseDouble("-13.1294607"), Double.parseDouble("-19.9602353"))); 43 | 44 | setUpMap(); 45 | 46 | plotMarkers(mMyMarkersArray); 47 | } 48 | 49 | private void plotMarkers(ArrayList markers) 50 | { 51 | if(markers.size() > 0) 52 | { 53 | for (MyMarker myMarker : markers) 54 | { 55 | 56 | // Create user marker with custom icon and other options 57 | MarkerOptions markerOption = new MarkerOptions().position(new LatLng(myMarker.getmLatitude(), myMarker.getmLongitude())); 58 | markerOption.icon(BitmapDescriptorFactory.fromResource(R.drawable.currentlocation_icon)); 59 | 60 | Marker currentMarker = mMap.addMarker(markerOption); 61 | mMarkersHashMap.put(currentMarker, myMarker); 62 | 63 | mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter()); 64 | } 65 | } 66 | } 67 | 68 | private int manageMarkerIcon(String markerIcon) 69 | { 70 | if (markerIcon.equals("icon1")) 71 | return R.drawable.icon1; 72 | else if(markerIcon.equals("icon2")) 73 | return R.drawable.icon2; 74 | else if(markerIcon.equals("icon3")) 75 | return R.drawable.icon3; 76 | else if(markerIcon.equals("icon4")) 77 | return R.drawable.icon4; 78 | else if(markerIcon.equals("icon5")) 79 | return R.drawable.icon5; 80 | else if(markerIcon.equals("icon6")) 81 | return R.drawable.icon6; 82 | else if(markerIcon.equals("icon7")) 83 | return R.drawable.icon7; 84 | else 85 | return R.drawable.icondefault; 86 | } 87 | 88 | 89 | private void setUpMap() 90 | { 91 | // Do a null check to confirm that we have not already instantiated the map. 92 | if (mMap == null) 93 | { 94 | // Try to obtain the map from the SupportMapFragment. 95 | mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 96 | 97 | // Check if we were successful in obtaining the map. 98 | 99 | if (mMap != null) 100 | { 101 | mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() 102 | { 103 | @Override 104 | public boolean onMarkerClick(com.google.android.gms.maps.model.Marker marker) 105 | { 106 | marker.showInfoWindow(); 107 | return true; 108 | } 109 | }); 110 | } 111 | else 112 | Toast.makeText(getApplicationContext(), "Unable to create Maps", Toast.LENGTH_SHORT).show(); 113 | } 114 | } 115 | 116 | public class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter 117 | { 118 | public MarkerInfoWindowAdapter() 119 | { 120 | } 121 | 122 | @Override 123 | public View getInfoWindow(Marker marker) 124 | { 125 | return null; 126 | } 127 | 128 | @Override 129 | public View getInfoContents(Marker marker) 130 | { 131 | View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null); 132 | 133 | MyMarker myMarker = mMarkersHashMap.get(marker); 134 | 135 | ImageView markerIcon = (ImageView) v.findViewById(R.id.marker_icon); 136 | 137 | TextView markerLabel = (TextView)v.findViewById(R.id.marker_label); 138 | 139 | TextView anotherLabel = (TextView)v.findViewById(R.id.another_label); 140 | 141 | markerIcon.setImageResource(manageMarkerIcon(myMarker.getmIcon())); 142 | 143 | markerLabel.setText(myMarker.getmLabel()); 144 | anotherLabel.setText("A custom text"); 145 | 146 | return v; 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /java/com/rogcg/androidgmaps/MyMarker.java: -------------------------------------------------------------------------------- 1 | package com.rogcg.androidgmaps; 2 | 3 | public class MyMarker 4 | { 5 | private String mLabel; 6 | private String mIcon; 7 | private Double mLatitude; 8 | private Double mLongitude; 9 | 10 | public MyMarker(String label, String icon, Double latitude, Double longitude) 11 | { 12 | this.mLabel = label; 13 | this.mLatitude = latitude; 14 | this.mLongitude = longitude; 15 | this.mIcon = icon; 16 | } 17 | 18 | public String getmLabel() 19 | { 20 | return mLabel; 21 | } 22 | 23 | public void setmLabel(String mLabel) 24 | { 25 | this.mLabel = mLabel; 26 | } 27 | 28 | public String getmIcon() 29 | { 30 | return mIcon; 31 | } 32 | 33 | public void setmIcon(String icon) 34 | { 35 | this.mIcon = icon; 36 | } 37 | 38 | public Double getmLatitude() 39 | { 40 | return mLatitude; 41 | } 42 | 43 | public void setmLatitude(Double mLatitude) 44 | { 45 | this.mLatitude = mLatitude; 46 | } 47 | 48 | public Double getmLongitude() 49 | { 50 | return mLongitude; 51 | } 52 | 53 | public void setmLongitude(Double mLongitude) 54 | { 55 | this.mLongitude = mLongitude; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /res/drawable-hdpi/currentlocation_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-hdpi/currentlocation_icon.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-hdpi/icon1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-hdpi/icon1.png -------------------------------------------------------------------------------- /res/drawable-hdpi/icon2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-hdpi/icon2.jpeg -------------------------------------------------------------------------------- /res/drawable-hdpi/icon3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-hdpi/icon3.gif -------------------------------------------------------------------------------- /res/drawable-hdpi/icon4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-hdpi/icon4.png -------------------------------------------------------------------------------- /res/drawable-hdpi/icon5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-hdpi/icon5.gif -------------------------------------------------------------------------------- /res/drawable-hdpi/icon6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-hdpi/icon6.png -------------------------------------------------------------------------------- /res/drawable-hdpi/icon7.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-hdpi/icon7.gif -------------------------------------------------------------------------------- /res/drawable-hdpi/icondefault.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-hdpi/icondefault.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogcg/android-googlemaps-custom-markers/f3f257b8a8baef31713401f2a342c118260734d2/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /res/layout/infowindow_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 18 | 19 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 10 | 11 | -------------------------------------------------------------------------------- /res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 7 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AndroidGmaps 5 | Hello world! 6 | Settings 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | --------------------------------------------------------------------------------