0

I have a similar problem with Google maps API V3 - multiple markers on exact same spot. I have read @ DzinX 's answer and try to use it. But it seems my lat and lng cannot use "+". But when i try "*", it worked. The datatype of lat and lng is float(tried double and decimal also). Any reason why?

for (var i = 0; i < locations.length; i++) {
  lat = locations[i][0];
  lng = locations[i][1]

  var marker = new google.maps.Marker({position: new google.maps.LatLng(lat*2, lng),  icon: 'images/markers_red.png'
                });
      markers.push(marker);
      marker.setMap(map);

    }
Community
  • 1
  • 1
user2462090
  • 119
  • 1
  • 1
  • 12
  • So your issue is trying to add two floats together, not to do with the Google Maps API? – Jared Jul 18 '13 at 04:12
  • "The datatype of lat and lng is float(tried double and decimal also)." I don't think so. JavaScript does not have any of those types. It has a `number` type and a `string` type among others. What do `typeof lat` and `typeof lng` evaluate to? – Michael Geary Jul 18 '13 at 04:16
  • @Jared any idea how to add two floats together? – user2462090 Jul 18 '13 at 04:16
  • @MichaelGeary i mean in database – user2462090 Jul 18 '13 at 04:17
  • JavaScript doesn't know anything about your database. It doesn't know what types you use in the database. All it knows is what's actually sent down to the browser. – Michael Geary Jul 18 '13 at 04:18
  • If `*` does what you expect, but `+` doesn't, it may likely mean that you don't have `number` values, but `string` values instead. Check `typeof lat` and `typeof lng`. – Michael Geary Jul 18 '13 at 04:22
  • Programming languages (such as JavaScript) are pretty forgiving and will usually convert the variable's type to the one required for the calculation. You can force a variable to be a float by calling `parseFloat(x)`. – Jared Jul 18 '13 at 04:27
  • You could also be dealing with objects not floats. The Google Maps API will sometimes convert your floating latitudes and longitudes into an API-friendly object. Double-check you're dealing with floats. – Jared Jul 18 '13 at 04:29

0 Answers0