[GIS] How to set center of map in ArcGIS API for JavaScript using Lat Long

arcgis-javascript-api

I am using Arcgis javascript API for my map where map is coming from arcgis online using map by ID.
Now I want to set map center using Lat long,For this I am using this method to set map center

   map.centerAt(42.58,78.25);

But this method is not working for me.
Does anybody know how to set map center using Lat Long In Arcgis javascript API.

Best Answer

the centerAt() method expects a point geometry object.

//pass long,lat and don't forget to load the appropriate AMD module
map.centerAt(new Point(-118.15, 33.80));
//or
map.centerAt(new Point(-118.15, 33.80, new SpatialReference(4326)));

this is mentioned in the API reference: https://developers.arcgis.com/javascript/jsapi/map-amd.html#centerat

the object can be constructed using WGS84 coordinates without specifying a spatial reference, but it doesn't hurt anything to include it.

https://developers.arcgis.com/javascript/jsapi/point-amd.html