Mapbox Plugin

This plugin allows you display mapviews from the Mapbox SDK. You can add custom mapview styles to the mapviews.

Platforms:

this plugin only works on iOS via Corona Simulator and Android and iOS via Corona native (see how to build for Corona Native below)

Functions:

mapbox.init(accessToken)

access token from mapbox account

mapbox.newView(params)

(Note this does not return anything, obj is returned in listener

params(table)

  • x (number) x corona point of mapview
  • y (number) y corona point of mapview
  • width (number) width of mapview
  • height (number) height of mapview
  • listener (number) returns Mapview and other events
    • event.type == "obj", event.obj =(Mapbox Mapview) returns a mapview object with all it Proporties and Methods down bellow
    • event.type == "regionChange", event.phase == "began", "moving", or "ended", event.lat = (number) returns latitude, event.lng= (number) returns longitude
    • event.type == "annotationInfoClicked", event.annotationLat = (number) returns latitude, event.annotationLng= (number) returns longitude, event.annotationTitle = (string) title of annotation clicked, event.annotationSubtitle = (string) Subtitle of annotation clicked, event.annotationSubtitle = (string) Subtitle of annotation clicked
  • style (string)(optional) default if "light", other options are custom mapbox style, "dark", "emerald", "hybrid", "streets", or "satellite"
  • hideLogo (boolean)(optional) default if false
  • hideAttribution (boolean)(optional) default if false
  • hideCompass (boolean)(optional) default if false
  • rotateEnabled (boolean)(optional) default if true
  • scrollEnabled (boolean)(optional) default if true
  • zoomEnabled (boolean)(optional) default if true
  • showsUserLocation (boolean)(optional) default if false (note requires location on device see bellow)
  • allowsTilting (boolean)(optional) default if true

Mapbox Mapview Proporties:

x (number) x corona point of mapview

y (number) y corona point of mapview

width (number) width of mapview

height (number) height of mapview

hideLogo (boolean)

hideAttribution (boolean)

hideCompass (boolean)

rotateEnabled (boolean)

scrollEnabled (boolean)

zoomEnabled (boolean)

showsUserLocation (boolean) (note requires location on device see bellow)

allowsTilting (boolean)

Mapbox Mapview Method:

:getZoom(listener)

listener(function) returns event.zoom(number)

:setZoom(zoom)

zoom(number) set zoom for map

:setCenter(lat, lng)

lat(number) latitude of map

lng(number) longitude of map

:getCenter(listener)

listener(function) returns event.lat, event.lng

:animateCamera(params)

params(table)

  • lat(number) latitude to animate to
  • lng(number) longitude to animate to
  • duration(number)(optional) time of animation (measured in seconds), deafult is 10
  • tilt(number)(optional) toward the horizon measured in degrees
  • bearing(number)(optional) measured in degrees clockwise from true north

:addMarkers(markers)

markers(array) array of tables with the following params

  • lat(number) latitude to pin marker to
  • lng(number) longitude to pin marker to
  • title(number)(optional) title to add to pin
  • subtitle(number)(optional) subtitle to add to pin

:removeAllMarkers()-- remove all markers from map

:hide()-- hide map

:unhide()-- unhide map

:setFollowMode(mode) (note requires location on device see bellow)

mode(string) "follow", "disable"

:disableUserInteraction(shouldDisable)

shouldDisable(boolean)

:destroyView()-- destroy map

User Location:

In order to use the location on iOS, You need permission from user to use location. You have to add NSLocationWhenInUseUsageDescription to Info.plist. You can use mapbox.requestLocationServices() to request access and then mapbox.locationServicesEnabled()-- returns string ("denied"(iOS), "granted"(iOS), "restricted"(iOS parental controls prevent access), "not determined"(iOS you have not requested access))

Corona Native:

For ios check out this corona tutorial

On android, you must add the mapview plugin to your gradle

Then run this script in the terminal to download the plugin, edit the script to your project path.

Build Settings:

Helpful Links:

Get Plugin

Example

Support