Select to view content in your preferred language

Snap to Intersection

1042
3
Jump to solution
10-21-2013 03:04 PM
RayEvans
New Contributor
I am working on a web app to allow users to reverse geocode addresses. Using the samples, I have been able to do this with non-intersections, but at times the users will want to click on the map and return an intersection address (ie W 4th St AND Pine St).  Is there a way to 'snap to' an intersection, or select the nearest intersection? I've looked through the samples and I've not found what I'm looking for.  Any help/advice would be appreciated.
0 Kudos
1 Solution

Accepted Solutions
RayEvans
New Contributor
thanks for the info, I was afraid that might be the case, luckily, the web app is a .NET web app, so I was able to make an AJAX call to a page that takes the coordinates for the address that was clicked and returns the nearest intersection. 
For anyone else looking to do the same, here's basically what I did

.NET Code behind, takes an X and Y (as double)
      Dim endpoint As String = "http://<myurl>/GeocodeServer"       Using gc As New ESRI.ArcGIS.ADF.ArcGISServer.GeocodeServerProxy(endpoint)          Dim point As New PointN()          point.X = X          point.Y = Y          ' Set reverse geocode search parameters          Dim revGeocodeProp As PropertySetProperty = New PropertySetProperty()          revGeocodeProp.Key = "ReverseDistanceUnits"          revGeocodeProp.Value = "Meters"           Dim revGeocodeProp1 As PropertySetProperty = New PropertySetProperty()          revGeocodeProp1.Key = "ReverseDistance"          revGeocodeProp1.Value = "1000"          Dim propArray As PropertySetProperty() = New PropertySetProperty() {revGeocodeProp, revGeocodeProp1}          Dim revGeocodePropSet As New ESRI.ArcGIS.ADF.ArcGISServer.PropertySet()          revGeocodePropSet.PropertyArray = propArray           Dim results As ESRI.ArcGIS.ADF.ArcGISServer.PropertySet = gc.ReverseGeocode(point, True, revGeocodePropSet)           ' return JSON string based on results        End Using


Javascript code, after the location-to-address completes:
       if(dom.byId("cbIntersect").checked == true){     // make ajax call to find the nearest intersection     var qry = 'http://<addressTo.NETSite>/mypage.aspx?x=' + location.x + '&y=' + location.y;     $.ajax({        url: qry,        type: "get",        dataType: "html",        error: function() {},        beforeSend: function() {},        complete: function() {},        success: function(strData) {              if (JSON.parse(strData) != null && JSON.parse(strData).address != null) {                  address = JSON.parse(strData).address;                  location = JSON.parse(strData).location;                  setInfoWindow(address, location); // this just shows a pop-up window              }        }});          }

View solution in original post

0 Kudos
3 Replies
JohnGravois
Deactivated User
the REST spec for geocode.arcgis.com for reverseGeocoding doesn't seem to include any parameters to specify that you want an intersection as opposed to an interpolated address, so im not sure how you'd accomplish something like that.

'snapping' itself wouldn't be a relevant solution unless you loaded your entire collection of reference data into the application as graphics layers, which would probably be pretty cumbersome.
0 Kudos
RayEvans
New Contributor
thanks for the info, I was afraid that might be the case, luckily, the web app is a .NET web app, so I was able to make an AJAX call to a page that takes the coordinates for the address that was clicked and returns the nearest intersection. 
For anyone else looking to do the same, here's basically what I did

.NET Code behind, takes an X and Y (as double)
      Dim endpoint As String = "http://<myurl>/GeocodeServer"       Using gc As New ESRI.ArcGIS.ADF.ArcGISServer.GeocodeServerProxy(endpoint)          Dim point As New PointN()          point.X = X          point.Y = Y          ' Set reverse geocode search parameters          Dim revGeocodeProp As PropertySetProperty = New PropertySetProperty()          revGeocodeProp.Key = "ReverseDistanceUnits"          revGeocodeProp.Value = "Meters"           Dim revGeocodeProp1 As PropertySetProperty = New PropertySetProperty()          revGeocodeProp1.Key = "ReverseDistance"          revGeocodeProp1.Value = "1000"          Dim propArray As PropertySetProperty() = New PropertySetProperty() {revGeocodeProp, revGeocodeProp1}          Dim revGeocodePropSet As New ESRI.ArcGIS.ADF.ArcGISServer.PropertySet()          revGeocodePropSet.PropertyArray = propArray           Dim results As ESRI.ArcGIS.ADF.ArcGISServer.PropertySet = gc.ReverseGeocode(point, True, revGeocodePropSet)           ' return JSON string based on results        End Using


Javascript code, after the location-to-address completes:
       if(dom.byId("cbIntersect").checked == true){     // make ajax call to find the nearest intersection     var qry = 'http://<addressTo.NETSite>/mypage.aspx?x=' + location.x + '&y=' + location.y;     $.ajax({        url: qry,        type: "get",        dataType: "html",        error: function() {},        beforeSend: function() {},        complete: function() {},        success: function(strData) {              if (JSON.parse(strData) != null && JSON.parse(strData).address != null) {                  address = JSON.parse(strData).address;                  location = JSON.parse(strData).location;                  setInfoWindow(address, location); // this just shows a pop-up window              }        }});          }
0 Kudos
JohnGravois
Deactivated User
yup.  the reverseGeocode operation in SOAP definitely allows you to pass a boolean asking specifically for intersections.

Geocode service ReverseGeocode method - ReturnIntersection
http://resources.arcgis.com/en/help/soap/10.2/#/ReverseGeocode/01vp000000n6000000/

nice work!
0 Kudos