Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
How to stop a user initiating multiple calls to google map api

I have come across an issue with google maps.

I have an HTML form which displays a large amount of data for a user. The form is split into a concertina layout, with each concertina responsible for showing different aspects of the user's data.

One of these concertinas holds the user's address and a google map with several pins representing pertinent information.

If the form is loaded, and the concertina is closed, then google map <div> has no vertical height on which to calculate zoom settings and I end up with a map that is zoomed to the extents of the planet. If the concertina is open when the form is loaded then zoom works fine (because the map <div> has height).

This is a well known feature/bug. One way to get around this is to load the google map when the user opens the concertina or if the concertina is open when the form is loaded.

What I need to achieve: I need to prevent multiple calls to google maps to 'reload' the map if the user opens and closes the concertina multiple times (without refreshing the form).

Here is a fiddle: https://jsfiddle.net/fdnuopzv/4/

As you can see the google map is loaded EVERY time the concertina opens. I need to detect that the map exists so that it shows the existing map rather than going and getting a fresh one.

I tried using:

if (!google.map) {
  map_init();
}

but this does not have the desired affect.

As a point of interest if you move the map_init() line from line 10 to line 65 you can see how a zero height breaks the google zoom.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is pretty lo-fi, but one option is to check the container for an iframe ...

if ($('#accordianarea' + thisId).find('iframe').length===0) map_init();

https://jsfiddle.net/kinglish/cw2Lamxr/5/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!