Select to view content in your preferred language

Displaying coordinates on MAP

2116
11
Jump to solution
05-20-2014 11:13 PM
AshishYadav
Deactivated User
Greetings to all,

I had been working with Google Maps for displaying coordinates till now, but then came across ARCGIS and was exited to work with this. Started a day or two ago, came across a strange behavior and i am desperate to get a work around on this.

The coordinates (30.7764803800,76.0161244300) points out to place X in INDIA where as the same represents a place in AFRICA.

Looking forward to some assistance on this.

Thanks
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
AaronNash1
Frequent Contributor
I created a quick app and attached is a screen shot, I am experiencing the same behavior as you. The coordinates are not in the same projection as your basemap and it is causing map point be displayed in Africa. Here is some code for reprojecting a mappoint into the same coordinate system as the basemap, this should work with any basemap.

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"       xmlns:s="library://ns.adobe.com/flex/spark"       xmlns:esri="http://www.esri.com/2008/ags">  <s:layout>   <s:VerticalLayout horizontalAlign="center"/>  </s:layout>  <fx:Script>   <![CDATA[    import com.esri.ags.Graphic;    import com.esri.ags.Map;    import com.esri.ags.SpatialReference;    import com.esri.ags.events.GeometryServiceEvent;    import com.esri.ags.geometry.MapPoint;    import com.esri.ags.symbols.SimpleMarkerSymbol;    import com.esri.ags.tasks.GeometryService;    import com.esri.ags.tasks.supportClasses.ProjectParameters;         //create the mappoint using the lat and long    private function createPoint():void     {      var testPoint:MapPoint = new MapPoint(76.0161244300, 30.7764803800);     //spatial reference of the mappoint     testPoint.spatialReference = new SpatialReference(4326);      var projParams:ProjectParameters = new ProjectParameters();     projParams.geometries = [testPoint];     //reproject to map spatial reference     projParams.outSpatialReference = myMap.spatialReference;     geometryService.project(projParams);         }         //reproject event     private function projectCompleteHandler(event:GeometryServiceEvent):void    {      try     {      // Note: As of version 2.0, GeometryService returns geometries (instead of graphics)            var pt:MapPoint = (event.result as Array)[0]as MapPoint;      var ptGraphic:Graphic = new Graphic(null, new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 22, 0x009933));      ptGraphic.geometry = pt;       myGraphicsLayer.clear()      myGraphicsLayer.add(ptGraphic);     }     catch (error:Error)     {      //Alert.show(error.toString());     }    }    ]]>  </fx:Script>  <fx:Declarations>   <esri:GeometryService id="geometryService" showBusyCursor="false" projectComplete="projectCompleteHandler(event)"            url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/>  </fx:Declarations>  <s:controlBarLayout>   <s:VerticalLayout gap="10" paddingBottom="7" paddingLeft="10" paddingRight="10" paddingTop="7"/>  </s:controlBarLayout>  <s:controlBarContent>   <s:Button id="btn" click="createPoint()" label="Add some more markers using ActionScript"/>  </s:controlBarContent>  <esri:Map id="myMap" level="2" wrapAround180="true">   <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>   <esri:GraphicsLayer id="myGraphicsLayer"/>  </esri:Map> </s:Application>


Also built into the ESRI Flex API is the ability to translate Latitude and Longitude into webmercator without having to make a call to a geometry service. If you are using the ESRI basemaps (which are in webmercator) then here is the code to create a mappoint that will put the point where it is supposed to go

var testPoint:WebMercatorMapPoint = new WebMercatorMapPoint(76.0161244300, 30.7764803800);

hope that helps

View solution in original post

0 Kudos
11 Replies
AaronNash1
Frequent Contributor
if you posted your code it might be easier for someone to help
0 Kudos
KomanDiabate
Deactivated User
You should still post your code,  but I think you are flip-flopping your coordinates. (See attachment).


[ATTACH=CONFIG]33969[/ATTACH]
0 Kudos
AshishYadav
Deactivated User
Hi @nasha001 @kdiabate64,


This is what i have written in the code:

var myGraphicPoint:Graphic = new Graphic(new MapPoint(30.7764803800, 76.0161244300, new SpatialReference(4326)));
     myGraphicPoint.symbol = pictureMarker;
     myGraphicsLayer.add(myGraphicPoint);

The X&Y here are static values passed as shown in the attachment shared by @kdiabate64.
I saw the attachment shared by @hdiabate64 and that is what Google Map shows at my end too but its the way around as shown in the attachment share below using ARCGIS.

Looking forward to hear from you.


Thanks
0 Kudos
PaulHastings1
Deactivated User
google's points are constructed latitude, longitude (y,x) vs ESRI's longitude, latitude (x,y).  kdiabate64
is correct, your coords are swapped.
0 Kudos
AshishYadav
Deactivated User
Hi Paul,

Swapping the coords to

var myGraphicPoint:Graphic = new Graphic(new MapPoint(76.0161244300, 30.7764803800, new SpatialReference(4326)));
myGraphicPoint.symbol = pictureMarker;
myGraphicsLayer.add(myGraphicPoint);

doesn't changes anything for me... I wonder if everything else is correct or not..

Looking forward to hear from you.


Thanks
0 Kudos
AaronNash1
Frequent Contributor
I created a quick app and attached is a screen shot, I am experiencing the same behavior as you. The coordinates are not in the same projection as your basemap and it is causing map point be displayed in Africa. Here is some code for reprojecting a mappoint into the same coordinate system as the basemap, this should work with any basemap.

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"       xmlns:s="library://ns.adobe.com/flex/spark"       xmlns:esri="http://www.esri.com/2008/ags">  <s:layout>   <s:VerticalLayout horizontalAlign="center"/>  </s:layout>  <fx:Script>   <![CDATA[    import com.esri.ags.Graphic;    import com.esri.ags.Map;    import com.esri.ags.SpatialReference;    import com.esri.ags.events.GeometryServiceEvent;    import com.esri.ags.geometry.MapPoint;    import com.esri.ags.symbols.SimpleMarkerSymbol;    import com.esri.ags.tasks.GeometryService;    import com.esri.ags.tasks.supportClasses.ProjectParameters;         //create the mappoint using the lat and long    private function createPoint():void     {      var testPoint:MapPoint = new MapPoint(76.0161244300, 30.7764803800);     //spatial reference of the mappoint     testPoint.spatialReference = new SpatialReference(4326);      var projParams:ProjectParameters = new ProjectParameters();     projParams.geometries = [testPoint];     //reproject to map spatial reference     projParams.outSpatialReference = myMap.spatialReference;     geometryService.project(projParams);         }         //reproject event     private function projectCompleteHandler(event:GeometryServiceEvent):void    {      try     {      // Note: As of version 2.0, GeometryService returns geometries (instead of graphics)            var pt:MapPoint = (event.result as Array)[0]as MapPoint;      var ptGraphic:Graphic = new Graphic(null, new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 22, 0x009933));      ptGraphic.geometry = pt;       myGraphicsLayer.clear()      myGraphicsLayer.add(ptGraphic);     }     catch (error:Error)     {      //Alert.show(error.toString());     }    }    ]]>  </fx:Script>  <fx:Declarations>   <esri:GeometryService id="geometryService" showBusyCursor="false" projectComplete="projectCompleteHandler(event)"            url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"/>  </fx:Declarations>  <s:controlBarLayout>   <s:VerticalLayout gap="10" paddingBottom="7" paddingLeft="10" paddingRight="10" paddingTop="7"/>  </s:controlBarLayout>  <s:controlBarContent>   <s:Button id="btn" click="createPoint()" label="Add some more markers using ActionScript"/>  </s:controlBarContent>  <esri:Map id="myMap" level="2" wrapAround180="true">   <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>   <esri:GraphicsLayer id="myGraphicsLayer"/>  </esri:Map> </s:Application>


Also built into the ESRI Flex API is the ability to translate Latitude and Longitude into webmercator without having to make a call to a geometry service. If you are using the ESRI basemaps (which are in webmercator) then here is the code to create a mappoint that will put the point where it is supposed to go

var testPoint:WebMercatorMapPoint = new WebMercatorMapPoint(76.0161244300, 30.7764803800);

hope that helps
0 Kudos
SamarthGupta
Deactivated User
If i have to display polylines using the same co-ordinates then how will i provide my co-ordinates to polyline mappoint

This is the general way of placing polyline on ArcGIS map:

myPolyline = new Polyline([[new mapPoint(x, y), new mapPoint(x, y)]], new SpatialReference(4326));
var myGraphicLine:Graphic = new Graphic(myPolyline);
myGraphicLine.symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, 0xFF0000, 1.0, 4);
myGraphicsLayer.add(myGraphicLine);
0 Kudos
AshishYadav
Deactivated User
Hi,

@nasha001 that was quick and awesome, sorry for replying late but it did work just smooth as i wanted it to be.
However, i am facing another concern and seeking your or everybody's help again.

How can i connect two map points on the MAP with a polyline(as its done in Google Maps).
The following code is what i had tried:

myPolyline = new Polyline([[new mapPoint(x, y), new mapPoint(x, y)]], new SpatialReference(4326));
var myGraphicLine:Graphic = new Graphic(myPolyline);
myGraphicLine.symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, 0xFF0000, 1.0, 4);
myGraphicsLayer.add(myGraphicLine);

Thanks
0 Kudos
AaronNash1
Frequent Contributor
where it says new MapPoint, just put in your x and y like below. There is a good sample here
var myPolyline:Polyline = new Polyline(
                    [[
                     new MapPoint(-1726185, 9543036),
                     new MapPoint(34923, 6920940),
                     new MapPoint(1874303, 6255632),
                     new MapPoint(1835168, 6255632),
                     new MapPoint(1913439, 6138225)
                     ]], new SpatialReference(102100));
                var myGraphicLine:Graphic = new Graphic(myPolyline);
                myGraphicLine.symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASH, 0xDD2222, 1.0, 4);
                myGraphicsLayer.add(myGraphicLine);
0 Kudos