apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

Weird latitude problem Javascript #429

Closed harold-s closed 10 years ago

harold-s commented 10 years ago

Hello,

I cannot reproduce the problem on a simple Google map so I guess the problem comes from Google-Maps-for-Rails.

I have over 5000 coordinates in my database and if I display them all on one map, it works flawlessly except for one point that moves aound after each refresh. It's longitude seems to be OK each time but the latitude is wrong.

The coordinates of the point are : lat:45.5531, lng: 3.74324

If I display this point 11 times on the same map, I get 11 different points with different latitudes.

image

Here is the code I use to display this map :

<div id="map_compte" class='gmap' style='width: 900px; height: 300px;'></div>

<script>
//<![CDATA[

handler = Gmaps.build('Google');
handler.buildMap({ internal: {id: 'map_compte', streetViewControl: false}}, function(){
  markers = handler.addMarkers([{"lat":45.5531,"lng":3.74324,"marker_title":"pin","picture":{"url":"/assets/home_blue.png","width":36,"height":36},"infowindow":"pin"},{"lat":45.5531,"lng":3.74324,"marker_title":"pin","picture":{"url":"/assets/home_orange.png","width":36,"height":36},"infowindow":"pin"},{"lat":45.5531,"lng":3.74324,"marker_title":"pin","picture":{"url":"/assets/home_orange.png","width":36,"height":36},"infowindow":"pin"},{"lat":45.5531,"lng":3.74324,"marker_title":"pin","picture":{"url":"/assets/home_orange.png","width":36,"height":36},"infowindow":"pin"},{"lat":45.5531,"lng":3.74324,"marker_title":"pin","picture":{"url":"/assets/home_green.png","width":36,"height":36},"infowindow":"pin"},{"lat":45.5531,"lng":3.74324,"marker_title":"pin","picture":{"url":"/assets/home_orange.png","width":36,"height":36},"infowindow":"pin"},{"lat":45.5531,"lng":3.74324,"marker_title":"pin","picture":{"url":"/assets/home_light-green.png","width":36,"height":36},"infowindow":"pin"},{"lat":45.5531,"lng":3.74324,"marker_title":"pin","picture":{"url":"/assets/home_orange.png","width":36,"height":36},"infowindow":"pin"},{"lat":45.5531,"lng":3.74324,"marker_title":"pin","picture":{"url":"/assets/home_orange.png","width":36,"height":36},"infowindow":"pin"},{"lat":45.5531,"lng":3.74324,"marker_title":"pin","picture":{"url":"/assets/home_orange.png","width":36,"height":36},"infowindow":"pin"},{"lat":45.5531,"lng":3.74324,"marker_title":"pin","picture":{"url":"/assets/home_orange.png","width":36,"height":36},"infowindow":"pin"}]);
  handler.bounds.extendWith(markers);
  handler.fitMapToBounds();
  handler.map.streetViewControl = false;
});

//]]>
</script>

Could you help me please ?

Thanks a lot !!!

apneadiving commented 10 years ago

upgrade to 2.1.2, should work directly :)

apneadiving commented 10 years ago

btw, watch out:

handler.buildMap({ internal: {id: 'map_compte', streetViewControl: false}}

should be:

handler.buildMap({ internal: {id: 'map_compte'}, provider: {streetViewControl: false}}
harold-s commented 10 years ago

Hello,

Thanks for Streetview !

I have upgraded to 2.1.2 in my project :

bundle show | grep gmap

But I still have the problem.

apneadiving commented 10 years ago

Ok I didnt understand your issue before. I've tried your code:

handler = Gmaps.build('Google');
handler.buildMap({ internal: {id: 'map'}}, function(){
  markers = handler.addMarkers([
    {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"},
    {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"},
    {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"},
    {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"},
    {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"},
    {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"},
    {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"},
    {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"},
    {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"},
    {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"},
    {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"}
    ]);
  handler.bounds.extendWith(markers);
  handler.fitMapToBounds();
});

and get: image

So sorry but I cant reproduce.

harold-s commented 10 years ago

Thanks !

I have minified the code with the bug :

I have linked underscore-min.js to their website

I have put gmaps_google.js on pastebin (http://pastebin.com/raw.php?i=ae1qhTTF)

Here's what I get :

image

Here is the HTML :

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />

<script src="http://maps.google.com/maps/api/js?v=3.13&amp;sensor=false&amp;libraries=geometry" type="text/javascript"></script>
<script src='http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script>
<script src="http://www.google.com/jsapi"></script>
</head>

<body>
<script src="http://pastebin.com/raw.php?i=ae1qhTTF"></script>
<script src="http://underscorejs.org/underscore-min.js"></script>

<div id="map_compte" class='gmap' style='width: 100%; height: 300px;'></div>

<script>
//<![CDATA[

handler = Gmaps.build('Google');
handler.buildMap({ internal: {id: 'map_compte'}, provider: {streetViewControl: false}}, function(){
  markers = handler.addMarkers([{"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"}, {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"}, {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"}, {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"}, {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"}, {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"}, {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"}, {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"}, {"lat":45.5531,"lng":3.74324,"marker_title":"pin","infowindow":"pin"}]);
  handler.bounds.extendWith(markers);
  handler.fitMapToBounds();
});

//]]>
</script>

</body>
</html>
apneadiving commented 10 years ago

Replace:

<script src="http://pastebin.com/raw.php?i=ae1qhTTF"></script>

With:

<script src="http://apneadiving.github.io/js/gmaps4rails.js" type='text/javascript'></script>
apneadiving commented 10 years ago

(its the 2.1.2 version)

harold-s commented 10 years ago

Thanks it works !

I had a few versions of the old javascript hiding and conflicting with the new one.

Thanks a lot !