Geocoding with another countries information

949
9
Jump to solution
06-24-2013 12:46 PM
RyanWhiley
New Contributor
Hello,

Right now I am currently working in another country trying to set up a web application that can search addresses.  I have looked through the samples and attempted to manipulate them so that they work with me, but I was unable to.  Along with that, I am not able to access the database that supplies the information for one of the samples (links are at the bottom) and so I am not able to see the fields that are in that database.  I am able to tell that there is at least a score and locatorName field, neither of which I have.  I have an Adres field where the address is stored, and a Point section where the X and Y coordinates are stored.  But that is about it.  Below is a copy of the JS I have. So I was wondering how I would go about building this with the amount of information I have.  I am not the most fluent in JS, but any help would be greatly appreciated.   

<script>       dojo.require("esri.map");       dojo.require("esri.tasks.locator");       dojo.require("dojo.number");       dojo.require("dijit.form.Button");       dojo.require("dijit.form.Textarea");       dojo.require("dijit.layout.BorderContainer");       dojo.require("dijit.layout.ContentPane");    dojo.require("esri.layers.FeatureLayer");              var map;        function init() {         map = new esri.Map("map", {            basemap: "topo",           center: [-68.95921478269354, 12.201009750494986],           zoom: 11         });      var opLayer1 = new esri.layers.ArcGISDynamicMapServiceLayer(            "ihavetherightlinkbutcannotputithere/rest/services/FeatureServer", {   opacity:0.4,   basemap:"topo"   });   map.addLayer(opLayer1);                    var locator = new esri.tasks.Locator("http://ihavetherightlinkbutcannotputithere/rest/services/FeatureServer");         dojo.connect(locator, "onAddressToLocationsComplete", showResults);                  map.infoWindow.resize(200,125);       }        function locate() {         map.graphics.clear();         var address = {"SingleLine":dojo.byId("Adres").value};         locator.outSpatialReference= map.spatialReference;         var Adres = {           address:Adres,                    }         locator.addressToLocations(Adres);       }        function showResults(candidates) {         var candidate;         var symbol = new esri.symbol.SimpleMarkerSymbol();         var infoTemplate = new esri.InfoTemplate( "Address: ${Adres}");          symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE);         symbol.setColor(new dojo.Color([153,0,51,0.75]));          var geom;                  dojo.every(candidates,function(candidate){                        console.log(candidate.Adres);             var attributes = { address: candidate.Adres };                geom = candidate.Adres;             var graphic = new esri.Graphic(geom, symbol, attributes, infoTemplate);             //add a graphic to the map at the geocoded location             map.graphics.add(graphic);             //add a text symbol to the map listing the location of the matched address.             var displayText = candidate.Adres;             var font = new esri.symbol.Font("16pt",esri.symbol.Font.STYLE_NORMAL, esri.symbol.Font.VARIANT_NORMAL,esri.symbol.Font.WEIGHT_BOLD,"Helvetica");                         var textSymbol = new esri.symbol.TextSymbol(displayText,font,new dojo.Color("#666633"));             textSymbol.setOffset(0,8);             map.graphics.add(new esri.Graphic(geom, textSymbol));             return false; //break out of loop after one candidate with score greater  than 80 is found.                    });         if(geom !== undefined){           map.centerAndZoom(geom,12);         }        }       dojo.ready(init);     </script>



The sample I've been working with:
https://developers.arcgis.com/en/javascript/jssamples/locator_address.html


And the link that is disabled:
http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer



Also, here is a list of the fields I have available:

    OBJECTID (Type: esriFieldTypeOID, Alias: OBJECTID)
    Buurten (EN:Neighborhood) (Type: esriFieldTypeString, Alias: Buurten, Length: 250 )
    B_STATUS (Type: esriFieldTypeString, Alias: B_STATUS, Length: 255 )
    FUNCTIE (EN:Type of building) (Type: esriFieldTypeString, Alias: FUNCTIE, Length: 255 )
    Straatnaam_conc (En:Streetname) (Type: esriFieldTypeString, Alias: Straatnaam_conc, Length: 250 )
    Adres (EN:Address) (Type: esriFieldTypeString, Alias: Adres, Length: 100 )
    Shape (Type: esriFieldTypeGeometry, Alias: Shape)

        Point:
           X: ##.###
           Y: ##.###



Thank you,
Ryan
0 Kudos
1 Solution

Accepted Solutions
JohnGravois
Frequent Contributor
results is actually an array of features, so typing something like results.feature into the console after setting a breakpoint in the app returns "undefined". 

you could use results[0].feature to specify the feature in the array at index position 0 (or in english, the first result in the list), but this doesn't return a geometry object either.

[ATTACH=CONFIG]25477[/ATTACH]

in order to get a geometry object, you have to dig into the properties of the returned feature itself (ie. results[0].feature.geometry)

the more comfortable you get navigating our API reference and using the developer tools in the browser to set breakpoints and interrogate variables, the less this stuff seems like black magic. 

good luck with the rest of your project!

View solution in original post

0 Kudos
9 Replies
JohnGravois
Frequent Contributor
var locator = new esri.tasks.Locator("http://ihavetherightlinkbutcannotputithere/rest/services/FeatureServer");


you can't geocode against feature services, only geocoding services.
0 Kudos
RyanWhiley
New Contributor
Hi John, thanks for the reply.

I am not sure a geocode server will work out here because the addresses do not follow a regular order like they do in The States.  The addresses are just in a random order.  Would it still work despite that? 

If not I was thinking I may have to make some sort of find attribute function and then have another that zooms to said attribute, would this work if the geocode server does not?

Thanks,
Ryan
0 Kudos
JohnGravois
Frequent Contributor
im not sure i understand what you mean by "attribute function", but you can definitely query any individual feature layer in a map service by attributes and return exact matches. 

the purpose of a geocoding service is to translate addresses (even when they aren't an exact match to what exists in your reference data) into the most accurate location possible.  this is typically done with centerlines that have address ranges defined in the attribute table, but an address locator can also be created using point data from individual addresses.
0 Kudos
RyanWhiley
New Contributor
Alright, thank you.  I have actually got something working with a MapServer where I altered the code to This Application and my program does virtually the same thing that application does, except mine has the proper data that I need.  And when I enter an address it returns the proper address and symbolizes it on the map.  But I was wondering if it is possible to autozoom to that location after the result is returned.

Pretty much exactly like the Geocoding an Address application.  Except that one uses Geocoding and I am not sure if that is going to make a difference or not. 

Thank you,
Ryan
0 Kudos
JohnGravois
Frequent Contributor
definitely possible.

in our geocoding sample, within the showResults function, we set the variable "geom" equal to the location of the returned address candidate (the location property returns a geometry object) prior to passing this information within a call to the function map.centerAndZoom().  in order to do something similar in your app, you'll have to figure out a way to get a reference to a similarly appropriate geometry object.

geom = candidate.location;
...
//first make sure that the geometry of the returned address is actually defined
if(geom !== undefined){
    map.centerAndZoom(geom,12);
}
0 Kudos
RyanWhiley
New Contributor
I just did that and referenced geom to result.feature.  And now it is simply shrinking the width of the map and displacing the layers from the basemap a little.  Am I able to use map.centerAndZoom(geom,12); when I am not using a GeocodeServer? 

I was also looking through this thread, Zoom to Query, and trying some of the stuff in there but was unable to get any of that to work as well.  When I would plug in some new code, the map would just not show up.
0 Kudos
JohnGravois
Frequent Contributor
results is actually an array of features, so typing something like results.feature into the console after setting a breakpoint in the app returns "undefined". 

you could use results[0].feature to specify the feature in the array at index position 0 (or in english, the first result in the list), but this doesn't return a geometry object either.

[ATTACH=CONFIG]25477[/ATTACH]

in order to get a geometry object, you have to dig into the properties of the returned feature itself (ie. results[0].feature.geometry)

the more comfortable you get navigating our API reference and using the developer tools in the browser to set breakpoints and interrogate variables, the less this stuff seems like black magic. 

good luck with the rest of your project!
0 Kudos
RyanWhiley
New Contributor
Awesome, it works perfectly.


Thank you for all your assistance.
0 Kudos
JohnGravois
Frequent Contributor
you're very welcome.  please consider marking this thread as "answered" 🙂
0 Kudos