[android] #5631 - add a concrete java exception when creating a marker without the required position field.
[android] #5631 - updated test cases to handle invalid position on a Marker
This commit is contained in:
committed by
Tobrun Van Nuland
parent
5fb0e878b4
commit
fd5ee40506
@@ -4,6 +4,7 @@ import android.graphics.Bitmap;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
|
||||
@@ -70,6 +71,10 @@ public final class MarkerOptions extends BaseMarkerOptions<Marker, MarkerOptions
|
||||
* @return Marker The build marker
|
||||
*/
|
||||
public Marker getMarker() {
|
||||
if (position == null) {
|
||||
throw new InvalidMarkerPositionException();
|
||||
}
|
||||
|
||||
marker.setPosition(position);
|
||||
marker.setSnippet(snippet);
|
||||
marker.setTitle(title);
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.graphics.Bitmap;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
/**
|
||||
@@ -73,6 +74,10 @@ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerV
|
||||
|
||||
@Override
|
||||
public MarkerView getMarker() {
|
||||
if (position == null) {
|
||||
throw new InvalidMarkerPositionException();
|
||||
}
|
||||
|
||||
marker.setPosition(position);
|
||||
marker.setSnippet(snippet);
|
||||
marker.setTitle(title);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.mapbox.mapboxsdk.exceptions;
|
||||
|
||||
public class InvalidMarkerPositionException extends RuntimeException {
|
||||
|
||||
public InvalidMarkerPositionException() {
|
||||
super("Adding an invalid Marker to a Map. " +
|
||||
"Missing the required position field. " +
|
||||
"Provide a non null LatLng as position to the Marker.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user