Title: How can I get access to the map instance using javascript?
Last modified: October 18, 2023

---

# How can I get access to the map instance using javascript?

 *  Resolved [jonantonio](https://wordpress.org/support/users/jonantonio/)
 * (@jonantonio)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/how-can-i-get-access-to-the-map-instance-using-javascript/)
 * Hi,
 * Our client using your plugin, is it possible to get reference the map instance
   so I can create a custom search script using js.
 * Thank you
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fhow-can-i-get-access-to-the-map-instance-using-javascript%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [DylanAuty](https://wordpress.org/support/users/dylanauty/)
 * (@dylanauty)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/how-can-i-get-access-to-the-map-instance-using-javascript/#post-17134784)
 * Hi [@jonantonio](https://wordpress.org/support/users/jonantonio/),
 * Thank you for getting in touch, we do appreciate your time.
 * Yes, you can access the map instance directly via JavaScript by two primary methods,
   which I’ll showcase below.
 * **Instance by Array**
 *     ```wp-block-code
       // Get map by map instance array
       const map = WPGMZA.maps[0];
       ```
   
 * **Instance by ID**
 *     ```wp-block-code
       // Get map by map ID
       const map = WPGMZA.getMapByID(2);
       ```
   
 * You can access these once the page is ready, but you may find it difficult to
   bind events in this way, and instead we recommend you bind to one of our event
   listeners.
 * We might recommend “**init.wpgmza**” or “**markersplaced.wpgmza**“, which would
   be bound via a jQuery event listener:
 *     ```wp-block-code
       // Wait for markers to be placed on the map 
       jQuery(($) => {
         $(document.body).on('markersplaced.wpgmza', () => {
           // Process here
         });
       });
       ```
   
 * I hope this helps?
 *  Thread Starter [jonantonio](https://wordpress.org/support/users/jonantonio/)
 * (@jonantonio)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/how-can-i-get-access-to-the-map-instance-using-javascript/#post-17134962)
 * Hi Dylan,
 * Thank you for your insightful answers, really helped me a lot. 
   Is it possible
   to do programmatical search using javascript?
 * Regards
 * Jon
 *  Plugin Author [DylanAuty](https://wordpress.org/support/users/dylanauty/)
 * (@dylanauty)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/how-can-i-get-access-to-the-map-instance-using-javascript/#post-17136203)
 * Hi [@jonantonio](https://wordpress.org/support/users/jonantonio/),
 * Only a pleasure, happy to help!
 * You can trigger the search via the JavaScript API, but it is often simpler to
   trigger a button click for the search button on your existing search form.
 * I had a look at your page and it seems that you have gone that direction. ☺

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How can I get access to the map instance using javascript?’ 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/)

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * 3 replies
 * 2 participants
 * Last reply from: [DylanAuty](https://wordpress.org/support/users/dylanauty/)
 * Last activity: [2 years, 7 months ago](https://wordpress.org/support/topic/how-can-i-get-access-to-the-map-instance-using-javascript/#post-17136203)
 * Status: resolved