Please note that caution has to be used when manipulating the Maps Marker Pro database directly via the API to avoid data loss. All calls are immediate and cannot be undone.
To use the DB API, we first have to instantiate the class:
$db = new MMP\DB();
Retrieving maps and markers:
Maps return objects with the following properties:
id: ID name: Name settings: An object containing the map settings (JSON encoded) filters: An object containing the map filters (JSON encoded) created_by: The name of the user who created the map created_on: The date and time when the map was created updated_by: The name of the user who last updated the map updated_on: The date and time when the map was last updated markers: The number of markers that are assigned to this map (if requested)
Markers return objects with the following properties:
id: ID name: Name address: Address lat: Latitude lng: Longitude zoom: Zoom icon: Icon filename popup: Popup contents link: URL to be opened instead of showing a popup created_by: The name of the user who created the marker created_on: The date and time when the marker was created updated_by: The name of the user who last updated the marker updated_on: The date and time when the marker was last updated maps: Array of map IDs that the marker is assigned to
Retrieves a single map. The first argument is the ID of the map we want to retrieve. The second argument indicates whether we also want to count the assigned markers. This defaults to false and should only be set to true if the marker count is needed, as it slows down the request. Returns
null on error.
Retrieves a single marker. The first argument is the ID of the marker we want to retrieve.
null on error.
Get the map with ID 1, change the name, width and height and save the changes
$map = $db->get_map(1); $map->name = 'Car dealerships'; $settings = json_decode($map->settings); $settings->width = 640; $settings->height = 480; $map->settings = json_encode($settings); $db->update_map($map, 1);
Get the marker with ID 1, change the name, icon and popup and save the changes
$marker = $db->get_marker(1); $marker->name = 'Dealership 1'; $marker->icon = 'car.png'; $marker->popup = '<a href="https://example.com">Dealership 1 website</a>'; $db->update_marker($marker, 1);
FYI – the database API docs are not fully completed yet, for further information please have a look at the related function in /classes/db.php