0

Trying to center the map at a certain coordinates but map only centers at 0,0 instead. Coordinates are in decimal degrees. Code below.

function foo(data) {
 var lon = data.address.longitude;
 var lat = data.address.latitude;
 var coord = [lat,lon];
 var point = new esri.geometry.Point(coord) 
 console.log(point)
 map.centerAt(point);
 };
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 7, 2015 at 14:59
4
  • possible that your map is displaying in web mercator (aka google projection) and lat/lon need projecting before you centerAt Commented Jul 7, 2015 at 15:10
  • Even when I give a spatial reference like so it still does not pan to the correct location. var point = new esri.geometry.Point(coord, 102100) Commented Jul 7, 2015 at 15:39
  • You'll have to project the point to Web Mercator using the built-in tool geographicToWebMercator. Commented Jul 7, 2015 at 15:44
  • If you're not using web mercator, make sure it matches whatever coordinate system you assigned. Commented Jul 7, 2015 at 16:43

1 Answer 1

2

im going to have to disagree with everyone in the comments.

if @mdown 's application loads web mercator tiles, he can pass a long/lat pair to map.centerAt() and skip declaring the spatial reference entirely because the API assumes WGS84 when nothing else is specified (docced here) and is able to reproject the values appropriately on the fly.

http://jsbin.com/yogugecago/edit?html,output

in the code sample above, he's passing longitude and latitude in the wrong order.

answered Jul 8, 2015 at 18:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.