public interface MapProvider

Known subtypesWebMapProvider

The service-provider interface a native map backend implements so the core NativeMap component can drive it without knowing which provider (Apple MapKit, Google Maps, Bing, Huawei, …) is in use.

This is a plain interface, deliberately not a com.codename1.system.NativeInterface: core neither ships nor references any concrete implementation. When the developer selects a provider with the maps.provider build hint, the build pushes a provider implementation (carrying the platform-native methods) into the com.codename1.maps package of the app and weaves in a call to MapProviderRegistry.register(MapProvider). Absent that injection the registry stays empty and NativeMap falls back to the pure-vector MapView.

Every method is keyed by a mapId so a single provider implementation can serve multiple NativeMap instances. Coordinate conversion uses a stateful “calculate then read” idiom (calcScreenPosition then getScreenX / getScreenY) to avoid returning multiple values across the native boundary. Native code reports user interaction back through the static callbacks on NativeMap (fireTap, fireLongPress, fireMarkerClick, fireCameraChange, fireMapReady).

Fields

public static final int MAP_TYPE_STANDARD = 0Map type: standard street map.
public static final int MAP_TYPE_SATELLITE = 1Map type: satellite imagery.
public static final int MAP_TYPE_HYBRID = 2Map type: hybrid imagery with labels.
public static final int MAP_TYPE_TERRAIN = 3Map type: terrain relief.

Methods

public abstract String getId()A stable identifier for this provider, e.g. "apple" or "google".
public abstract boolean isAvailable()Whether this provider can render on the current device right now (e.g. Google checks that Play Services is present).
public abstract Component createPeer(NativeMap host, int mapId)Creates the view for the map identified by mapId.
public abstract void deinitialize(int mapId)Releases native resources for mapId when the map is no longer used.
public abstract void setCamera(int mapId, double lat, double lon, float zoom, float bearing, float tilt)Moves the camera.
public abstract double getLatitude(int mapId)
public abstract double getLongitude(int mapId)
public abstract float getZoom(int mapId)
public abstract float getMaxZoom(int mapId)
public abstract float getMinZoom(int mapId)
public abstract long addMarker(int mapId, byte[] icon, double lat, double lon, String title, String snippet, float anchorU, float anchorV)Adds a marker.
public abstract long beginPath(int mapId)Starts accumulating a path; feed it with addToPath.
public abstract void addToPath(int mapId, long pathId, double lat, double lon)
public abstract long finishPolyline(int mapId, long pathId, int strokeColor, int strokeWidth)Finishes the path as a stroked polyline and returns its element key.
public abstract long finishPolygon(int mapId, long pathId, int fillColor, int strokeColor, int strokeWidth)Finishes the path as a filled polygon and returns its element key.
public abstract long addCircle(int mapId, double lat, double lon, double radiusMeters, int fillColor, int strokeColor, int strokeWidth)Adds a geodesic circle and returns its element key.
public abstract void removeElement(int mapId, long elementId)
public abstract void removeAllElements(int mapId)
public abstract void calcScreenPosition(int mapId, double lat, double lon)
public abstract int getScreenX(int mapId)
public abstract int getScreenY(int mapId)
public abstract void calcLatLongPosition(int mapId, int x, int y)
public abstract double getScreenLat(int mapId)
public abstract double getScreenLon(int mapId)
public abstract void setShowMyLocation(int mapId, boolean show)
public abstract void setRotateGestureEnabled(int mapId, boolean enabled)
public abstract void setMapType(int mapId, int type)

Field details

MAP_TYPE_STANDARD

public static final int MAP_TYPE_STANDARD = 0
Map type: standard street map.

MAP_TYPE_SATELLITE

public static final int MAP_TYPE_SATELLITE = 1
Map type: satellite imagery.

MAP_TYPE_HYBRID

public static final int MAP_TYPE_HYBRID = 2
Map type: hybrid imagery with labels.

MAP_TYPE_TERRAIN

public static final int MAP_TYPE_TERRAIN = 3
Map type: terrain relief.

Method details

getId

public abstract String getId()
A stable identifier for this provider, e.g. "apple" or "google".

isAvailable

public abstract boolean isAvailable()
Whether this provider can render on the current device right now (e.g. Google checks that Play Services is present). When this returns false NativeMap falls back to the vector engine.

createPeer

public abstract Component createPeer(NativeMap host, int mapId)
Creates the view for the map identified by mapId. Native providers return a PeerComponent wrapping the native map view; a web-SDK provider returns a BrowserComponent. Either way it is a Component the NativeMap adds to its layout. Returning null triggers the vector fallback.

deinitialize

public abstract void deinitialize(int mapId)
Releases native resources for mapId when the map is no longer used.

setCamera

public abstract void setCamera(int mapId, double lat, double lon, float zoom, float bearing, float tilt)
Moves the camera. bearing and tilt are in degrees; providers that do not support them ignore those arguments.

getLatitude

public abstract double getLatitude(int mapId)

getLongitude

public abstract double getLongitude(int mapId)

getZoom

public abstract float getZoom(int mapId)

getMaxZoom

public abstract float getMaxZoom(int mapId)

getMinZoom

public abstract float getMinZoom(int mapId)

addMarker

public abstract long addMarker(int mapId, byte[] icon, double lat, double lon, String title, String snippet, float anchorU, float anchorV)
Adds a marker. icon is PNG bytes (or null for the default pin); returns an opaque element key. anchorU/anchorV are normalized.

beginPath

public abstract long beginPath(int mapId)
Starts accumulating a path; feed it with addToPath.

addToPath

public abstract void addToPath(int mapId, long pathId, double lat, double lon)

finishPolyline

public abstract long finishPolyline(int mapId, long pathId, int strokeColor, int strokeWidth)
Finishes the path as a stroked polyline and returns its element key.

finishPolygon

public abstract long finishPolygon(int mapId, long pathId, int fillColor, int strokeColor, int strokeWidth)
Finishes the path as a filled polygon and returns its element key.

addCircle

public abstract long addCircle(int mapId, double lat, double lon, double radiusMeters, int fillColor, int strokeColor, int strokeWidth)
Adds a geodesic circle and returns its element key.

removeElement

public abstract void removeElement(int mapId, long elementId)

removeAllElements

public abstract void removeAllElements(int mapId)

calcScreenPosition

public abstract void calcScreenPosition(int mapId, double lat, double lon)

getScreenX

public abstract int getScreenX(int mapId)

getScreenY

public abstract int getScreenY(int mapId)

calcLatLongPosition

public abstract void calcLatLongPosition(int mapId, int x, int y)

getScreenLat

public abstract double getScreenLat(int mapId)

getScreenLon

public abstract double getScreenLon(int mapId)

setShowMyLocation

public abstract void setShowMyLocation(int mapId, boolean show)

setRotateGestureEnabled

public abstract void setRotateGestureEnabled(int mapId, boolean enabled)

setMapType

public abstract void setMapType(int mapId, int type)