Adding a POI to a Mappress Map generated by a PHP Query

Home Forums MapPress Support Adding a POI to a Mappress Map generated by a PHP Query

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #15881

    Here is what I am trying to do: we are building a database to house organization listings, and each of these listings will have Mappress loaded onto them, to set up a Mashup of maps.

    We want the map to be centered based on the user’s location, and also create a POI for this location, that would get appended to the array. Here’s the code I have so far:

    $mymap = new Mappress_Map(array(“query” => array($searchkey => “$searchvalue”), “center” => array(“lat” => $_SESSION[‘lat’], “lng” => $_SESSION[‘long’]), “zoom” => 12, “width” => ‘100%’));
    echo $mymap->display();

    The code I have here works–based off of what the user inputs, the posts are correctly queried and the map is correctly centered on the lat/lng of the user’s current location.

    What I would like to do now is create an additional POI for the user’s location. I tried this code:

    $mypoi_1 = new Mappress_Poi(array(“iconid” => “green-dot”, “title” => “My Location”, “point” => array(“lat” => $_SESSION[‘lat’], “lng” => $_SESSION[‘long’])));
    $mymap->pois = array($mypoi_1);

    But it does not seem to do anything (I put it before echo $mymap->display();). I’m not entirely sure how to get this resolved. Is there a way to add a POI after the map has been generated?



    Hi Tom,

    When you use a query, the map POIs are read from the database and any POIs specified statically are ignored, that’s probably why you’re not seeing the additional marker.

    One approach that may work is to modify the POIs before they’re sent back to the map. You can use filter ‘mappress_map_display’ for that purpose – it’s passed each map just before the map is displayed, so you could probably add a POI there. I haven’t tested this, but here’s how it might look in functions.php:

    function mypoi($map) {
      $map->pois[] = new Mappress_Poi(array(“iconid” => “green-dot”, “title” => “My Location”, “point” => array(“lat” => $_SESSION[‘lat’], “lng” => $_SESSION[‘long’])));
    add_action('mappress_map_display', 'mypoi');

    Alternatively, you could use javascript to get a handle to the map and add a marker to it. For example if the map is named ‘mapp0’ (the default name for this 1st map, you can override it in the shortcode) the javascript would be:

    var gmap = mapp0.getMap();
    var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
    var marker = new google.maps.Marker({
          position: myLatlng,
          map: gmap,
          title: 'Hello World!'
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.