1

I'm trying to replicate this sample on my web map. I have been able to build it successfully as-is within VS 2010. However, I run into some issues when I try to get it to work with my services. I've successfully been able to display my map service, but I’m getting snagged up on the geocoding part. My geocode service is published and working fine (tested it within REST). Also, a ClientAccessPolicy.XML is on our server so I don't believe there are access issues.

On the xaml side of things, I've removed all but the Address stackpanel. I think my problems are arising on the C# side. This is the bit of code I believe is giving me troubles:

 private void FindAddressButton_Click(object sender, RoutedEventArgs e)
 {
 Locator locatorTask = new Locator("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
 "Locators/ESRI_Geocode_USA/GeocodeServer");
 locatorTask.AddressToLocationsCompleted += LocatorTask_AddressToLocationsCompleted;
 locatorTask.Failed += LocatorTask_Failed;
 AddressToLocationsParameters addressParams = new AddressToLocationsParameters();
 Dictionary<string, string> address = addressParams.Address; 
 if (!string.IsNullOrEmpty(State.Text))
 address.Add("Address", Address.Text);
 if (!string.IsNullOrEmpty(City.Text))
 address.Add("City", City.Text);
 if (!string.IsNullOrEmpty(State.Text))
 address.Add("State", State.Text);
 if (!string.IsNullOrEmpty(Zip.Text))
 address.Add("Zip", Zip.Text);
 if (addressParams.Address.Count == 0)
 {
 GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
 if (graphicsLayer !=null)
 graphicsLayer.ClearGraphics();
 CandidateScrollViewer.Content = null;
 CandidatePanelGrid.Visibility = Visibility.Collapsed;
 MessageBox.Show("No address field entered.");
 return;
 }
 locatorTask.AddressToLocationsAsync(addressParams);
 }

I've replaced the GeocodeServer URL with my service. A little further down are IF statements that deal with parameters and I’m not sure how to handle. I initially tried to remove all but the first IF statements, but I get errors when I go to interact with the map (it builds successfully). I'm not a programmer so I'm not sure how involved it would be make the manipulations necessary to get this function to work. In essence, all I need is a single input parameter, Address. I have successfully manipulated the xaml side to display a single input parameter, know I just need to manipulate C# code to make this work. Any help would be awesome.

asked Sep 19, 2012 at 22:09

1 Answer 1

2

Got it. I was using the wrong address field name. ESRI's address field for its geocoder is called "Address" While the name of my addres field is "Street".

 if (!string.IsNullOrEmpty(InputAddress.Text))
 address.Add("Street", InputAddress.Text);
 //if (!string.IsNullOrEmpty(City.Text))
 // address.Add("City", City.Text);
 //if (!string.IsNullOrEmpty(State.Text))
 // address.Add("State", State.Text);
 //if (!string.IsNullOrEmpty(Zip.Text))
 // address.Add("Zip", Zip.Text);
answered Sep 20, 2012 at 15:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.