0

I have a tile map like this .I would like to know the lat and long values (41.850033,-87.6500523) is located inside which tileBounds?

Am getting tile bounds values for every tile. but i dont know how to check if latitude is inside the range of particular tileBound value. how to find?

here is a working copy of my code

http://jsfiddle.net/doktormolle/55Nke/

 var div = ownerDocument.createElement('div');
  div.innerHTML = 
'<pre><strong>tile:\n['+tile.x+','+tile.y+']</strong>\
\nbounds:{\nsw:['+tileBounds.sw.lat+','+tileBounds.sw.lng+'],\
\nne:['+tileBounds.ne.lat+','+tileBounds.ne.lng+']\n}</pre>';
 div.style.width = this.tileSize.width + 'px';
 div.style.height = this.tileSize.height + 'px';
 div.style.fontSize = '10';
 div.style.borderStyle = 'solid';
 div.style.borderWidth = '1px';
 div.style.borderColor = '#AAAAAA';
 if(lat === 41.850033 && lng === -87.6500523){ //if latitude and longitude value inside that tile bounds set color as red
 div.style.backgroundColor='red';
  }
 return div;
};

how to check here if my latitude and longitude lies inside tileBounds.sw and tileBounds.ne?

var setTileBackground = 
this.mapDataPoints.some(function(el){
 return (tileBounds.sw.lat  <= el.latitude <= tileBounds.ne.lat && tileBounds.sw.lng <= el.longitude <= tileBounds.ne.lng)
            })    // never returns true ...

I solved my problem with this check

var setTileBackground = this.mapDataPoints.some(function(el){
 return (el.latitude > tileBounds.sw.lat && el.latitude < tileBounds.ne.lat  && el.longitude > tileBounds.sw.lng && 
 el.longitude < tileBounds.ne.lng)
                    });
Reinstate Monica Cellio
  • 25,975
  • 6
  • 51
  • 67
Riya
  • 199
  • 1
  • 2
  • 12
  • Maybe [this](https://stackoverflow.com/q/18295825/863110) question can help. – Mosh Feu Aug 30 '18 at 15:05
  • 1
    this solves my problem ..... var setTileBackground = this.mapData.some(function(el){ return (el.latitude > tileBounds.sw.lat && el.latitude < tileBounds.ne.lat && el.longitude > tileBounds.sw.lng && el.longitude < tileBounds.ne.lng) }); – Riya Aug 31 '18 at 07:46
  • 1
    You should post your solution as an actual Answer, not just part of the question. – Steve Bennett Aug 31 '18 at 08:08

0 Answers0