MapQuest Maps Android SDK


Put a Marker on the Map

Android with Map and Marker
public class MainActivity extends Activity {
    private final LatLng MAPQUEST_HEADQUARTERS_LOCATION = new LatLng(39.750307, -104.999472);
    private MapView mMapView;
    private MapboxMap mMapboxMap;

    protected void onCreate(Bundle savedInstanceState) {

        mMapView = (MapView) findViewById(;

        mMapView.getMapAsync(new OnMapReadyCallback() {
            public void onMapReady(MapboxMap mapboxMap) {
                mMapboxMap = mapboxMap;
                mMapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(MAPQUEST_HEADQUARTERS_LOCATION, 12));

    private void addMarker(MapboxMap mapboxMap) {
        MarkerOptions markerOptions = new MarkerOptions();
        markerOptions.snippet("Welcome to Denver!");

Adding annotations from MapQuest APIs

MapQuest provides a powerful set of APIs to work with our Maps SDKs such as geocoding, search, and navigation. Often you'll want to show annotations from a search ahead request or navigation stops.

In the sample below first sets the camera to the area around your current location, and then creates the Search Ahead instance. It passes in a search in the queryString around the current location and then puts markers on the map.

private void performSearch(String queryString, LocationResult locationResult) {

	Location lastLocation = locationResult.getLastLocation();
	mMapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude()), 10));

	if (mSearchAheadServiceV3 == null) {
		mSearchAheadServiceV3 = new SearchAheadService(this, BuildConfig.API_KEY);

	List<SearchCollection> searchCollections = Collections.singletonList(SearchCollection.POI);
	try {
		MQLatLng latLng = new MQLatLng(lastLocation);

		SearchAheadQuery query = new SearchAheadQuery.Builder(queryString, searchCollections).location(latLng).build();
				new SearchAheadService.SearchAheadResponseCallback() {

					public void onSuccess(@NonNull SearchAheadResponse searchAheadResponse) {

						MainActivity.this.runOnUiThread(() -> {
							for (SearchAheadResult result : searchAheadResponse.getResults()) {
								MarkerOptions markerOptions = new MarkerOptions();
								Place place = result.getPlace();
								AddressProperties aProp = place.getAddressProperties();

								String address = new StringBuilder()
										.append(StringUtils.defaultIfEmpty(aProp.getStreet(), "")).append("\n")
										.append(StringUtils.defaultIfEmpty(aProp.getCity(), "")).append(" ")
										.append(StringUtils.defaultIfEmpty(aProp.getStateCode(), "")).append( " ")
										.append(StringUtils.defaultIfEmpty(aProp.getPostalCode(), "")).append("\n")
								markerOptions.position( MBLatLngUtil.fromMQLatLng( place.getLatLng() ) );

					public void onError(Exception e) {
						L.e("Search Ahead V3 Failure", e);
	} catch (IllegalQueryParameterException e) {
		L.e("Error performing search", e);

The Search Ahead and Maps SDK have different LatLng classes so you will have to convert between them.

import com.mapbox.mapboxsdk.geometry.LatLng;

public final class MBLatLngUtil extends LatLng {

    static LatLng fromMQLatLng( latLng) {
        return new LatLng((double)latLng.getLatitude(), (double)latLng.getLongitude());

Responding to Marker Events

The MapQuest Android SDK provides a listener for capturing when a user taps on a marker. By default, all markers come with an onMarkerClick event listener for displaying and hiding info windows. You can override this default event listener and set your own with the setOnMarkerClickListener method.

mapboxMap.setOnMarkerClickListener(new MapboxMap.OnMarkerClickListener() {
  public boolean onMarkerClick(@NonNull Marker marker) {
    Toast.makeText(MainActivity.this, marker.getTitle(), Toast.LENGTH_LONG).show();
    return true;

Updating the Marker

private final LatLng CAMERA_LOC = new LatLng(39.745391, -105.00653);

// Change the marker location

// Update the marker icon