none
Bing Maps AJAX Controls V7 Positioning Bug RRS feed

  • Question

  • Hi all,

    I would report a bug that I've noticed 1 day ago on the Bing Maps AJAX Controls V7.

    The image below shows a pushpin object called self.youAreHere and a location object called self.centerCurrent that stores the location obtained by a map.getCenter() method.

    Bug Bing Maps

    I set the center of the map with the coordinates in self.youAreHere by the command map.setView({ center: self.youAreHere.getLocation() });

    As shown in the image there is a difference between the first set of coordinates and the second.

    Why? They should be the same!!!

    Thanks

    Thursday, September 26, 2013 2:15 PM

Answers

  • The difference can be attributed to floating point error in JavaScript. In any case, 6 decimal places has an accuracy of 10 centimetres on the map. All the other decimal places after the 6th one have no effect in where something is rendered on the map.


    http://rbrundritt.wordpress.com

    Thursday, September 26, 2013 4:47 PM
  • There is two ways to do this. One is to do a comparison of the coordinates rounded off to 5 or 6 decimal places like this:

    var coord1 = self.youAreHere.getLocation();
    var coord2 = self.centerCurrent();
    
    if(Math.round(coord1.latitude*100000)/10000 == Math.round(coord2.latitude*100000)/10000 &&
    Math.round(coord1.longitude*100000)/10000 == Math.round(coord2.longitude*100000)/1000){
    //They are equal
    }

    But even easier is to use the equals function on the Location object:

    http://msdn.microsoft.com/en-us/library/gg427612.aspx

    Microsoft.Maps.Location.areEqual(coord1, coord2)


    http://rbrundritt.wordpress.com

    Friday, September 27, 2013 9:36 AM

All replies

  • The difference can be attributed to floating point error in JavaScript. In any case, 6 decimal places has an accuracy of 10 centimetres on the map. All the other decimal places after the 6th one have no effect in where something is rendered on the map.


    http://rbrundritt.wordpress.com

    Thursday, September 26, 2013 4:47 PM
  • My aim is to check if the pushpin is centered, if not I show a "center pin on the map" button.

    Is there another solution to provide this feature?

    Thanks,

    Marco

    Thursday, September 26, 2013 4:56 PM
  • There is two ways to do this. One is to do a comparison of the coordinates rounded off to 5 or 6 decimal places like this:

    var coord1 = self.youAreHere.getLocation();
    var coord2 = self.centerCurrent();
    
    if(Math.round(coord1.latitude*100000)/10000 == Math.round(coord2.latitude*100000)/10000 &&
    Math.round(coord1.longitude*100000)/10000 == Math.round(coord2.longitude*100000)/1000){
    //They are equal
    }

    But even easier is to use the equals function on the Location object:

    http://msdn.microsoft.com/en-us/library/gg427612.aspx

    Microsoft.Maps.Location.areEqual(coord1, coord2)


    http://rbrundritt.wordpress.com

    Friday, September 27, 2013 9:36 AM
  • Thank you Ricky,

    very helpful!


    Friday, September 27, 2013 10:35 AM