Select to view content in your preferred language

Strange lat/long behaviour

2781
7
01-07-2013 12:53 PM
AlastairMoore
Emerging Contributor
Hi all,

I'm working on my first project with the ArcGIS Flex API and am running into some strange behaviour when I use lat/long values with the 4326 spatial reference.

The code I'm using for my map is as follows:


<esri:Map id="tourMap" width="640" height="680" top="120">
  <esri:extent>
    <esri:Extent xmin="16353106" ymin="-4312229" xmax="16356164" ymax="-4308981">
      <esri:SpatialReference wkid="102100" />
    </esri:Extent>
  </esri:extent>
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
  <esri:GraphicsLayer id="markerLayer"></esri:GraphicsLayer>
</esri:Map>


and I'm trying to place a marker as follows:


private function addMarkers():void {      
  // -36.076790, 146.918888
  // var marker:Graphic = new Graphic(new MapPoint(16354964, -4310639, new SpatialReference(102100)), new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE));
  var marker:Graphic = new Graphic(new MapPoint(146.905971, -36.069367, new SpatialReference(4326)), new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE));
  markerLayer.add(marker);
}


I'm finding using the 102100 spatial reference, the marker is place correctly, however the marker using 4326 spatial reference is being placed in the centre of the map every time, no matter what long/lat values I use.

I've also found that when I use the 4326 spatial reference to set the map extent values, the map always shows "map data not available".

Any help with this would be much appreciated!

Thanks very much in advance,

Alastair
Tags (2)
0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus
Alistair,

   Your issue is simply that you are trying to add a point to the map in WKID 4326 when the map is in 102100. This is not ArcMap, reprocecting does not happen automatically. You nee to add your point to the map in WKID 102100. Try using WebMercatorMapPoint like this:

            private function addMarkers():void {      
                // -36.076790, 146.918888
                // var marker:Graphic = new Graphic(new MapPoint(16354964, -4310639, new SpatialReference(102100)), new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE)); 
                var marker:Graphic = new Graphic(new WebMercatorMapPoint(146.905971, -36.069367), new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE));
                markerLayer.add(marker);
            }


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow these steps as shown in the below graphic:

0 Kudos
AlastairMoore
Emerging Contributor
Alistair,

   Your issue is simply that you are trying to add a point to the map in WKID 4326 when the map is in 102100. This is not ArcMap, reprocecting does not happen automatically. You nee to add your point to the map in WKID 102100. Try using WebMercatorMapPoint like this:

            private function addMarkers():void {      
                // -36.076790, 146.918888
                // var marker:Graphic = new Graphic(new MapPoint(16354964, -4310639, new SpatialReference(102100)), new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE)); 
                var marker:Graphic = new Graphic(new WebMercatorMapPoint(146.905971, -36.069367), new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE));
                markerLayer.add(marker);
            }


Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow these steps as shown in the below graphic:




Thanks very much, that's fixed it.
0 Kudos
TomRauch
Emerging Contributor
Hi, I am having similar issues, although I am using WeMercatorMap Point, see below.  I always seem to end up with a marker somewhere way off the correct location

var myGraphicMarker:Graphic = new Graphic(new WebMercatorMapPoint(latitude, longitude),
      new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 22, 0x009933));
    
      
     myGraphicsLayer.add(myGraphicMarker);
     myGraphicsLayer.refresh();

I have verified that "latitude" and "longitude" are valid numbers, they are in the form of (for example):

latitude = -32.994800
longitude = -68.529400

That should be Argentina, but I see my marker in the south pole!

and here is my extent

<esri:Extent id="initialExtent"
      xmin="-19325128.942" ymin="-10948057.675" xmax="-539964.871" ymax="18364625.427">
   <esri:SpatialReference wkid="102100"/>
  </esri:Extent>

and Map tags that call the initial extent

<esri:Map extent="{initialExtent}" wrapAround180="true" x="52" y="209" width="383" height="221">
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
  <esri:GraphicsLayer id="myGraphicsLayer"/>
</esri:Map>

Thanks for your help!
0 Kudos
AnthonyGiles
Honored Contributor
Tom,

You have your latitude and longitude the wrong way round in the webmercatormappoint function, see:

http://resources.arcgis.com/en/help/flex-api/apiref/index.html?com/esri/ags/geometry/WebMercatorMapP...

Try

New WebMercatorMapPoint(longitude,latitude)

Regards

Anthony
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Tom,

   WebMercatorMapPoint expects Lon then Lat in the constructor, is that your issue?
0 Kudos
TomRauch
Emerging Contributor
Anthony - brilliant!  Thanks 🙂
0 Kudos
AnthonyGiles
Honored Contributor
Tom,

Glad you got it to work, Please don't forget to mark the post as answered.

Regards

Anthony
0 Kudos