Select to view content in your preferred language

Reverse Geocode in ArcGIS JS API 4.x with additional parameters

1271
3
Jump to solution
02-05-2020 02:33 PM
by Anonymous User
Not applicable

Hi,

I'm trying to figure how to do reverse geocoding that will allow me to specify the exact object type I'd like to reverse geocode against. For example, in the rest api there is URL paramter for featureTypes = PointAddress. I don't want to reverse geocode against the street segment, just address points. I can't see this type of parameter in the JS API 4.14. I only see the location and locationType parameter in the API docs. Below is a sample block of code. 

let params = {
 location: evt.mapPoint,
 locationType: "rooftop"
 };
 geocoder.locationToAddress(params, options)
 .then(function(response) { // Show the address found
 console.log(response.attributes)
 // values to access to actual address value
 var address = response.attributes.Address + ', ' + response.attributes.City + ', ' + response.attributes.Region + ', ' + response.attributes.Postal;
 showPopup(address, evt.mapPoint);
 }, function(err) { // Show no address found
 showPopup("No address found.", evt.mapPoint);
 });
 }
 });
0 Kudos
1 Solution

Accepted Solutions
Noah-Sager
Esri Regular Contributor

Currently, featureTypes is not available as a parameter of the locationToAddress() method, but we are considering adding it at a later release. One alternative would be to add this parameter to the request using requestInterceptor.

doc: RequestInterceptor

View solution in original post

3 Replies
Noah-Sager
Esri Regular Contributor

Currently, featureTypes is not available as a parameter of the locationToAddress() method, but we are considering adding it at a later release. One alternative would be to add this parameter to the request using requestInterceptor.

doc: RequestInterceptor

by Anonymous User
Not applicable

Thanks Noah,

Appreciate the feedback I'll give the request interceptor a try!

0 Kudos
by Anonymous User
Not applicable

Noah Sager‌ definitely able to get it to work for one feature type:

esriConfig.request.interceptors.push({
  urls: "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer",
  before: function(params) {
    params.requestOptions.query.featureTypes = "PointAddress";
  }
});

Just curious if we can set multiple feature types. 

Thanks!

Dara