tostringtheory
tostringtheory

Reputation: 877

Google Maps markers disappearing randomly

I have been working on a script for a site that has 3 select lists, one for a degree quadrant (latitude, longitude). The idea is that when a user selects a degree quadrant, it prompts them if they want to use a map for lat/long minutes. If they opt in, a map is shown, and they can use the marker to indicate their position within that quadrant.

The problem is that sometimes when changing the degrees drop down, the marker will disappear from the map. Now, sometimes it seems to be pretty specific - once it fails on one, it doesn't appear to ever work for it. but if you keep changing the values around randomly, at some point, it gets 'unstuck' and works again, while others fail.

After checking the dev tools, it appears that the div that surrounds the google marker icon will sometimes blow up to full width, 0 height (approaching light speed apparently), and the image will disappear from its html.

What's even more odd, is that on those that fail to render, if I click around in the red quadrant, such as the upper left corner, a lot of times the marker will place itself there as it should. But then dragging the marker in the quadrant towards another corner, it disappears - no code should be running/handling dragging events. I cant explain this.

I have a JSFiddle to show this issue, and would appreciate anyone that can help me figure out what is going wrong. According to the script, after the marker position is set, i verify it in the console, and it still shows as what it was set to, so I don't know why it isn't working.

PS - Please excuse my JS code, as it is currently an experiment in Chaos theory while trying to get this to work.

Fiddle - http://jsfiddle.net/TkE87/light/

Result - http://jsfiddle.net/TkE87/embedded/result/

PSS - Please find below a test case that, at least for me, recreates all of these issues:

Select 25,82
Click use map
Select 25,81
Marker shown
Select 25,80
Marker gone
Select 24,80
Marker gone
Select 24,81
Marker shown
Select 24,80
Marker gone
Click in upper left corner
Drag marker towards right in red square
Marker disappears ~1/4 way in

Upvotes: 4

Views: 2154

Answers (1)

tostringtheory
tostringtheory

Reputation: 877

After some digging around in the API of Google Maps, I've concluded that this appears to be an error with the actual v3 script for Google Maps. I couldn't get the map to work correctly with workarounds by triggering resize events to redraw the map, much less anything else I tried. I ended up just having to recode the script to throw away the map, marker, bounds, and rectangles when the degrees select changed, and rebuild it from scratch everytime to ensure that the marker always shows up. Hideous, but unless someone from here/Google says otherwise and can provide a fix, that's the case I am left with.

Upvotes: 1

Related Questions