To import your own custom marker image into your Android application, you need to copy the image file file into the app / res / drawable folder of your Android project. In this example, we are using this image of our bus, but you can use any image you like.
Finally, we need a bit of code to set up our map and draw our marker. In the MapsActivity.java file, we’ll modify the setUpMap() function as follows:
private void setUpMap() {
LatLng busLocation = new LatLng(37.783879,-122.401254);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(busLocation, 12));
mMap.addMarker(new MarkerOptions()
.position(busLocation)
.title("Code the Road Bus")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.bus)));
}
You may also need to add the following import statements at the top of MapsActivity.java:
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
Click the Run button to run in an emulator or an attached Android device. You now have a fully working Android application with Google Maps!
Our application does not do too much right now, so be sure to read our follow-on posts where we’ll be adding a lot more capability to our app, such as
finding nearby places,
storing our road trip location history to the cloud, and
integrating with wearable devices. Stay tuned for more!