Title: Add marker dynamically with PHP
Last modified: June 16, 2018

---

# Add marker dynamically with PHP

 *  Resolved [weekendize](https://wordpress.org/support/users/weekendize/)
 * (@weekendize)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/)
 * Hey,
 * Is it possible to add marker dynamically with PHP? I want to display different
   stored locations depending on the filter selection of the user.
 * I’m currently using the free version but considering to upgrade to the pro version
   if my problem could be solved.
 * Best,
    Steffen

Viewing 15 replies - 1 through 15 (of 30 total)

1 [2](https://wordpress.org/support/topic/add-marker-dynamically-with-php/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/add-marker-dynamically-with-php/page/2/?output_format=md)

 *  [perryrylance](https://wordpress.org/support/users/perryrylance/)
 * (@perryrylance)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10410236)
 * Hi there
 * Thank you for getting in touch!
 * You can create markers in the database through `$wpdb`, our latest version includes
   experimental CRUD classes, you can use WPGMZA\Marker to add, delete and manipulate
   markers. These classes aren’t in use at the moment but they do work well.
 * My apologies that there is no documentation for this at the moment.
 * Does that answer your question?
 * Kind regards
    – Perry
 *  Thread Starter [weekendize](https://wordpress.org/support/users/weekendize/)
 * (@weekendize)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10410898)
 * Thanks for the quick response.
 * The users can filter entries based on specific attributes in the front-end. Depending
   on the filter I want to display all markers on a map that match the filtered 
   attribute. Therefore I need to dynamically create maps with changing markers 
   based on the filtered attributes.
 * Could I realize that with Map Mashup? If I have an empty parent map and add all
   matching entriees with the mashup_ids.
 * `echo do_shortcode('[wpgmza id="2" mashup=true mashup_ids=<matching entries> 
   parent_id="2"]);`
 * Is there any better solution for this problem?
 *  [perryrylance](https://wordpress.org/support/users/perryrylance/)
 * (@perryrylance)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10414697)
 * Hi there
 * Thanks for that,
 * I understand you want to filter and create dynamic maps, potentially using the
   mashup feature, but I’m not sure I quite follow.
 * Can you please describe in real, practical terms what the purpose of your application
   is?
 * I understand the technicalities, I may be able to offer better help if I can 
   get some context 🙂
 * Kind regards
    – Perry
 *  Thread Starter [weekendize](https://wordpress.org/support/users/weekendize/)
 * (@weekendize)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10415631)
 * Okay, we want to display products in the woocommerce shop page. Every product
   has an attribute „address“ which has the value of the products address (It‘s 
   more a bookable activity than a product). We could also add a lat and lng attribute
   that stores the location of the product.
 * The maximum products that are displayed on one page are 4. We want to show a 
   map with the markers of the actually displayed products. The user can filter 
   the products in the front-end. Therefore we have to customize the markers on 
   the map based on the actually displayed products.
 * The only solution that came in my mind was to create a map for every single product
   and use the Map Mashup to display a parent map in combination with the map of
   the actually displayed products.
 *  [perryrylance](https://wordpress.org/support/users/perryrylance/)
 * (@perryrylance)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10417435)
 * Hi there
 * We will be integrating with Woocommerce at some point in the future to address
   this, in the mean time the most optimal solution I can suggest would be the following:
 * – Set up a blank map on the page
    – Set up some Javascript on the page in question
   to send an AJAX request – Create an AJAX endpoint to receive a latitude and longitude–
   On that endpoint, find the nearest 4 locations to the given latitude and longitude–
   Return the title, address, latitude and longitude etc. to the Javascript module–
   For each result returned, call `WPGMZA.Marker.createInstance`, passing in the
   data received from the server
 * I can give you code to do the last steps, I’d have to see your database first
   hand to offer help on querying the Woocommerce products.
 * I hope that helps?
 * Kind regards
    – Perry
 *  Thread Starter [weekendize](https://wordpress.org/support/users/weekendize/)
 * (@weekendize)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10418129)
 * Perfect, thanks. I will give it a try.
    -  This reply was modified 7 years, 11 months ago by [weekendize](https://wordpress.org/support/users/weekendize/).
 *  Thread Starter [weekendize](https://wordpress.org/support/users/weekendize/)
 * (@weekendize)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10434570)
 * Hey Perry,
 * I have now the title, address, latitude and longitude etc. available in the module.
   What parameter do I have to pass to the function WPGMZA.Marker.createInstance?
   Or could you provide a short code snipplet?
 * Thanks in advance.
 * Steffen
 *  [perryrylance](https://wordpress.org/support/users/perryrylance/)
 * (@perryrylance)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10435940)
 * Hi Steffen
 * I’m glad to hear that’s working well!
 * WPGMZA.Marker.createInstance takes one parameter, which is a “settings” object.
 * Any data in there will be applied to the marker.
 * For each property on the object you pass in, if the marker has a property with
   the same name, it will be set there. Otherwise, it will be stored in the markers
   settings object.
 * For example:
 *     ```
       var marker = WPGMZA.Marker.createInstance({
        title: "Example marker",
        lat: 52,
        lng: -2,
        animation: WPGMZA.Marker.ANIMATION_BOUNCE,
        arbitraryProperty: "This will be stored on the settings object"
       });
       ```
   
 * I hope that helps?
 * Kind regards
    – Perry
 *  Thread Starter [weekendize](https://wordpress.org/support/users/weekendize/)
 * (@weekendize)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10546376)
 * Hi Perry,
 * sorry for the late reply, I was busy the last couple of weeks.
    How can I set
   up a blank map on the page with JavaScript? With the function WPGMZA.Map.createInstance()
   or just use a shortcode? Is there a documentation where I can look up the necessary
   parameters?
 * Thanks in advance.
    Steffen
 *  [perryrylance](https://wordpress.org/support/users/perryrylance/)
 * (@perryrylance)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10573930)
 * Hi Steffen
 * My apologies also for the delay in responding, I’ve been on leave for the last
   weke.
 * You can set up a blank map on a page using the shortcode, you could also technically
   use JavaScript, depending on your requirements.
 * Here is the [documentation on our shortcode paramaters](https://www.wpgmaps.com/documentation/advanced-map-options/map-shortcode-parameters/)
 * I hope that helps?
 * Kind regards
    – Perry
 *  Thread Starter [weekendize](https://wordpress.org/support/users/weekendize/)
 * (@weekendize)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10574949)
 * Thanks for your response.
    How can I create an empty map with JavaScript? Do 
   you provide any documentation/tutorial for your plugin regarding to JavaScript?
 *  [perryrylance](https://wordpress.org/support/users/perryrylance/)
 * (@perryrylance)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10574953)
 * Hi Steffen
 * We don’t provide any developer documentation at the moment, however we are working
   towards this.
 * You can create a map by creating a HTML element, and passing the element to WPGMZA.
   Map.createInstance like so
 * `var map = WPGMZA.Map.createInstance( document.getElementById("example") );`
 * I hope that helps?
 * Kind regards
    – Perry
 *  Thread Starter [weekendize](https://wordpress.org/support/users/weekendize/)
 * (@weekendize)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10575304)
 * Perfect, thanks!
    And how can I add the markers to the created map?
 *  [perryrylance](https://wordpress.org/support/users/perryrylance/)
 * (@perryrylance)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10577610)
 * Hi there
 * Please create a marker, passing the map as an option, or call `addMarker` on 
   the map afterwards:
 *     ```
       var marker = WPGMZA.Marker.createInstance({
        lat: 52,
        lng: -2
       });
       map.addMarker(marker);
       ```
   
 * I hope that helps?
 * Kind regards
    – Perry
 *  Thread Starter [weekendize](https://wordpress.org/support/users/weekendize/)
 * (@weekendize)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/#post-10579158)
 * I get the error “Uncaught ReferenceError: WPGMZA is not defined” when I use the
   functions in my ‘functions.php’ or in a seperated js file. What file do I need
   to include in order to use the functions?
 * Thanks in advance.

Viewing 15 replies - 1 through 15 (of 30 total)

1 [2](https://wordpress.org/support/topic/add-marker-dynamically-with-php/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/add-marker-dynamically-with-php/page/2/?output_format=md)

The topic ‘Add marker dynamically with PHP’ is closed to new replies.

 * ![](https://ps.w.org/wp-google-maps/assets/icon-256x256.png?rev=3058363)
 * [WP Go Maps - Google Maps, OpenStreetMap, Leaflet Map](https://wordpress.org/plugins/wp-google-maps/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-google-maps/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-google-maps/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-google-maps/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-google-maps/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-google-maps/reviews/)

 * 30 replies
 * 2 participants
 * Last reply from: [perryrylance](https://wordpress.org/support/users/perryrylance/)
 * Last activity: [7 years, 9 months ago](https://wordpress.org/support/topic/add-marker-dynamically-with-php/page/2/#post-10639824)
 * Status: resolved