Arcgis Online Geocoding service

4294
16
09-03-2015 12:49 AM
MaheshReddy
New Contributor

Hi All,

I am looking for an online web service to get Lat, Long values for the addresses using Arcgis Online Geocoding service. Please let me know if there is any dll or online web service to get the results using .Net Framework 4.0 and Visual Studio 2010.

Thank you,

Mahesh

0 Kudos
16 Replies
AnttiKajanus1
Occasional Contributor III

You can use ArcGIS Runtime for .NET to access the Geocoding service but it needs 4.5 framework to work. If you have to stay on 4.0 framework, you could have a look our older ArcGIS Runtime for WPF SDK. ​It support using locators too.

0 Kudos
MaheshReddy
New Contributor

Thanks for your reply.

While going through documentation, I found this link: http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates to get lat, long from the address provided. Can I use this link from .Net code?

If so, do I need to create a .Net wrapper for authentication and get token to get the results?

Yes, we have to use .Net framework 4.0 only. Is dll mandatory for using Geocoding service? Please let me know if there is any alternative way like using web services.

Thank you,

Mahesh

0 Kudos
AnttiKajanus1
Occasional Contributor III

One option is to write the task logic by hand and access the rest endpoint from your own code. We provide existing tasks in our SDK's to communicate with the service but in some cases rolling your own implementation might be an option.

If you want to go that route, please refer ArcGIS REST API: World Geocoding Service documentation for rest spec and authentication details.

0 Kudos
MaheshReddy
New Contributor

ArcGIS REST API should be good for my development purposes. As mentioned, I found following links: http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?<PARAMETERS> and https://www.arcgis.com/sharing/oauth2/token?client_id=<YOUR CLIENT ID>&grant_type=client_credentials&client_secret=<YOUR CLIENT SECRET>&f=pjson for authentication and generating token.

Can you help me out with a sample .Net code to generate token? Thanks for your help.

0 Kudos
AnttiKajanus1
Occasional Contributor III

We also provide out-of-the-box implementations for authentication in the SDK's but for more details how to implement it, please refer authentication documentation. What comes to c# implementation, you might want to check if there are 3rd party libraries that provides implementation for OAUTH 2.0.

0 Kudos
MaheshReddy
New Contributor

I am using following url to get lat, long: http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?Address=Sta... Pagar&Subregion=&Region=&CountryCode=SGP&outFields=Addr_type&maxLocations=1&forStorage=false&f=pjson and able to get the results, when Address is provided along with Country.

But for some addresses, require Lat, Long for Country only. However, when I just input country code, the result is not correct. For eg.,

http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?Address=&Ne.... Is there a way, we can get center of the Country geocodes?

Thank you.

0 Kudos
ThadTilton
Esri Contributor

I haven't had success either in getting a consistent geocode result using just a country code ("USA" seems to work, others do not).

There's an example on the developers.arcgis.com site that does this successfully  (https://developers.arcgis.com/en/features/geocoding/), but uses a combination of "suggest" (to get the desired country) and "find" (to retrieve the result).

One option is to simply query a country boundary service for the geometry and find the center (of the extent, e.g.). For example:

var queryUrl = "http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/World_Countries_(Generalized)/Featu...";

var queryTask = new QueryTask(new Uri(queryUrl));

var queryExp = "ISO = '" + this.CountryTextBox.Text + "'"; // SG, US, DK, for example (two-letter codes)

// var queryExp = "Country ='" + this.CountryTextBox.Text + "'"; // Singapore, United States, Denmark, for example

var countryQuery = new Query(queryExp);

var result = await queryTask.ExecuteAsync(countryQuery);

if (result.FeatureSet.Features.Count > 0)

{

    var countryExtent = result.FeatureSet.Features[0].Geometry.Extent as Envelope;

    var countryCenter = countryExtent.GetCenter();

    await this.MyMapView.SetViewAsync(countryCenter);

    MessageBox.Show("Center of '" +

                    this.CountryTextBox.Text + "' is " +

                    countryCenter.X.ToString() + " : " +

                    countryCenter.Y.ToString());

}

else

{

    MessageBox.Show("No results found for '" + this.CountryTextBox.Text + "'.");

}

0 Kudos
MaheshReddy
New Contributor

Thanks for your reply. Due to some issues, I cannot use ArcGIS runtime dll. Is there any rest url to get the results with countryCode.

Thanks in advance.

0 Kudos
dotMorten_esri
Esri Notable Contributor

I know this is slightly off topic, but would just like to point out that .NET 4.0 is losing support on January 12, 2016:

https://support.microsoft.com/en-us/lifecycle?sort=pn&alpha=.net%20framework

So you only have a few months left before you have to upgrade anyway.

0 Kudos