Problem with extent VEGeocoder returns

1313
5
09-27-2011 12:17 AM
GrzegorzChlodzinski
New Contributor
Hello,

It looks to me that it returns invalid results when it is being queried for strings like: USA, United States, North America.
For example when I use string USA, it sends the following request:
http://serverapi.arcgisonline.com/veadaptor/production/services/geocode/geocode?query=USA&token=<bing key>

Then the result it:
[
   {
      "address":{
         "countryRegion":"United States",
         "formattedAddress":"United States"
      },
      "bestView":{
         "xmin":177.348754882813,
         "ymin":26.6772079467773,
         "xmax":-55.848747253418,
         "ymax":75.7627944946289,
         "spatialReference":{
            "wkid":4326
         }
      },
      "confidence":"high",
      "displayName":"United States",
      "entityType":"Sovereign",
      "matchCodes":[
         "Good"
      ],
      "locationArray":[
         {
            "x":-98.9079971313477,
            "y":39.4500007629395,
            "calculationMethod":"Rooftop"
         }
      ]
   }
]


When I try to apply extent returned by 'bestView' (after converting to to web mercator using esri.geometry.geographicToWebMercator(bestView))
it takes me somewhere deep in Russia instead of showing USA.
Regular queries like 'Italy' etc works fine for me. Only the specific related to USA or North America seems to be returning invalid extent.
0 Kudos
5 Replies
derekswingley1
Frequent Contributor
Sounds like something that would be best answered by bing/microsoft since you're talking about a response from their service. Have you tried posting in their forum?
0 Kudos
GrzegorzChlodzinski
New Contributor
Before posting her I have checked what Bing returns (based on Bing REST API documentation found on MSDN).
It looks like Bing is going correct coordinates (although I am not sure how ArcGIS service is calling Bing).
Here's my call:
http://dev.virtualearth.net/REST/v1/Locations?o=xml&q=USA&key=<bing key>
and here's subset of returned data:
<BoundingBox>
[INDENT]<SouthLatitude>26.677207946777344</SouthLatitude><WestLongitude>177.3487548828125</WestLongitude><NorthLatitude>75.7627944946289</NorthLatitude><EastLongitude>-55.848747253417969</EastLongitude>
[/INDENT]
</BoundingBox>


My quess it that AcgGIS service incorrectly translates Bing result (VEGeocoder calls http://serverapi.arcgisonline.com url).
Is there any way you could verify it?
0 Kudos
derekswingley1
Frequent Contributor
Looks like the problem occurs when the extent specified by bestView crosses 180 degrees longitude. You end up with an extent where xmin > xmax. This obviously doesn't work...

Simple workaround would be to check for this and flip the sign on xmin if xmin > xmax:
var bv = geocodeResults[0].bestView;
if ( bv.xmin > bv.xmax ) {
  geocodeResults[0].bestView.xmin = bv.xmin * -1;
} 
map.setExtent(esri.geometry.geographicToWebMercator(geocodeResults[0].bestView));
0 Kudos
GrzegorzChlodzinski
New Contributor
This works.
Thank you for solving this problem!
0 Kudos
derekswingley1
Frequent Contributor
You're welcome!
0 Kudos