Address Locator error on Online Geocode service

2533
7
Jump to solution
04-04-2017 09:44 PM
MuhammadAfzal
New Contributor

I am using my owned prepared locator Geocode service (http://maps.dhalahore.org/ArcGIS/rest/services/DHAMAP/AddressLocator/GeocodeServer) in Geocode online (arcgis-appstudio-samples-master).

Working perfect on Reverse Geocoding but giving Error (Unable to complete operation. No Address Found) when i search any address in search box.

Here code:

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.2
import QtPositioning 5.3

import ArcGIS.AppFramework 1.0
import ArcGIS.AppFramework.Controls 1.0
import ArcGIS.AppFramework.Runtime 1.0
import ArcGIS.AppFramework.Runtime.Controls 1.0
import ArcGIS.AppFramework.Runtime 1.0

App {
    id: app
    width: 800
    height: 532

    property double scaleFactor: AppFramework.displayScaleFactor
    property string errorMsg

    Map {
        id: mainMap
        anchors.fill: parent
        extent: usExtent
        focus: true

        ArcGISTiledMapServiceLayer {
            url: "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
        }

        SimpleMarkerSymbol {
            id: simpleMarkerSymbolLocation
            color: "red"
            style: Enums.SimpleMarkerSymbolStyleCross
            size: 10
        }

        SimpleMarkerSymbol {
            id: simpleMarkerSymbolReverseLocation
            color: "blue"
            style: Enums.SimpleMarkerSymbolStyleDiamond
            size: 10
        }

        GraphicsLayer {
            id: graphicsLayerGeocode
        }

        GraphicsLayer {
            id: graphicsLayerReverse
        }

        Graphic {
            id: locationGraphicReverse
            symbol: simpleMarkerSymbolReverseLocation
        }

        Graphic {
            id: locationGraphicGeocode
            symbol: simpleMarkerSymbolLocation
        }

        Envelope {
            id: usExtent
            xMax: -15000000
            yMax: 2000000
            xMin: -7000000
            yMin: 8000000
            spatialReference: mainMap.spatialReference
        }

        onMouseClicked: {
            graphicsLayerReverse.removeAllGraphics();
            var graphic1 = locationGraphicReverse.clone();
            graphic1.geometry = mouse.mapPoint;
            graphicsLayerReverse.addGraphic(graphic1);
            locator.reverseGeocode(mouse.mapPoint, 500, mainMap.spatialReference);
        }
    }

    ServiceLocator {
        id: locator
        url: "http://maps.dhalahore.org/ArcGIS/rest/services/DHAMAP/AddressLocator/GeocodeServer"

        onFindStatusChanged: {
            if (findStatus === Enums.FindStatusCompleted) {
                progressBar.visible = false;
                if (findResults.length < 1) {
                    showError("No address Found");
                } else {
                    for (var i = 0; i < findResults.length; i++) {
                        var result = findResults;
                        var graphic = locationGraphicGeocode.clone()
                        graphic.geometry = result.location;
                        graphicsLayerGeocode.addGraphic(graphic);
                    }
                    mainMap.zoomTo(graphic.geometry);
                }
            } else if (findStatus === Enums.FindStatusErrored) {
                progressBar.visible = false;
                showError(findError.message + "\nNo Address Found");
            }
        }

        onReverseGeocodeStatusChanged: {
            if (reverseGeocodeStatus === Enums.ReverseGeocodeStatusCompleted) {
                searchBox.descriptionTextVisibility = true;
                searchBox.descriptionTextInput = "Address: "
                var address = reverseGeocodeResult.addressFields["Address"];
                var city = reverseGeocodeResult.addressFields["City"];
                var state = reverseGeocodeResult.addressFields["Region"];
                var zip = reverseGeocodeResult.addressFields["Postal"];
                searchBox.descriptionTextInput += address + " " + city + ", " + state + " " + zip;
            } else if (reverseGeocodeStatus === Enums.ReverseGeocodeStatusErrored) {
                showError(reverseGeocodeError.message + "\nNo Address Found");
                searchBox.descriptionTextVisibility = false;
            }
        }
    }

    LocatorFindParameters {
        id: findTextParams
        text: searchBox.searchTextInput
        outSR: mainMap.spatialReference
        maxLocations: 1
        searchExtent: usExtent
        sourceCountry: "US"
    }

    /*-----------------------------------------------------------------------------------------------------------------------
         Search button / box
         ---------------------------------------------------------------------------------------------------------------------*/

    SearchBox {
        id: searchBox

        anchors {
            left: parent.left
            top: parent.top
            margins: 20 * scaleFactor
        }

        onSearch: {
            findTextParams.text = searchBox.searchTextInput
            graphicsLayerGeocode.removeAllGraphics();
            locator.find(findTextParams);
            progressBar.visible = true;
        }

        onClear: {
            mainMap.extent = usExtent;
            mainMap.mapRotation = 0;
            graphicsLayerGeocode.removeAllGraphics();
            graphicsLayerReverse.removeAllGraphics();
            searchBox.descriptionTextInput = "";
            searchBox.searchTextInput.focus = true;
            searchBox.descriptionTextVisibility = false;
            searchBox.searchTextInput = "";
        }

        Keys.onReturnPressed: {
            findTextParams.text = searchBox.searchTextInput
            graphicsLayerGeocode.removeAllGraphics();
            locator.find(findTextParams);
            progressBar.visible = true;
            Qt.inputMethod.hide();
        }
    }

    Row {
        anchors {
            horizontalCenter: parent.horizontalCenter
            bottom: mainMap.bottom
            bottomMargin: 5 * scaleFactor
        }

        ProgressBar {
            id: progressBar
            indeterminate: true
            visible: false
        }
    }


    MessageDialog {
        id: messageDialog
        title: "Error"
        icon: StandardIcon.Warning
        modality: Qt.WindowModal
        standardButtons: StandardButton.Ok
        text: errorMsg
    }

    Rectangle {
        id: rectangleBorder
        anchors.fill: parent
        color: "transparent"
        border {
            width: 0.5 * scaleFactor
            color: "black"
        }
    }

    function showError(errorString) {
        errorMsg = errorString;
        messageDialog.visible = true;
    }
}

Any Info would be greatly appreciated.

Cheers,

"Tasadduq Hussain" 

0 Kudos
1 Solution

Accepted Solutions
nakulmanocha
Esri Regular Contributor
Hi there,

There are couple of issues here, directly related to your Geocoding service. 

1) Your geocoding service is based on server 10.0 and hence only supports FindAddressCandidates. Therefore you should be using 
 locator.geocode() method to perform Geocoding. This method calls the FindAddressCandidates operation

2) Based on your service address field. It currently takes Single Address labelled as "SingleKey". Hence you should only use that as your Address field parameter.

I have added these suggestions in your code and pasted below for your reference.

I hope this helps.

Thank you.
Nakul





App
{
    id: app
    width: 800
    height: 532
    property double scaleFactor: AppFramework.displayScaleFactor
    property string errorMsg
    Map {
        id: mainMap
        anchors.fill: parent
        extent: usExtent
        focus: true
        ArcGISTiledMapServiceLayer {
            url: "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
        }
        SimpleMarkerSymbol {
            id: simpleMarkerSymbolLocation
            color: "red"
            style: Enums.SimpleMarkerSymbolStyleCross
            size: 10
        }
        SimpleMarkerSymbol {
            id: simpleMarkerSymbolReverseLocation
            color: "blue"
            style: Enums.SimpleMarkerSymbolStyleDiamond
            size: 10
        }
        GraphicsLayer {
            id: graphicsLayerGeocode
        }
        GraphicsLayer {
            id: graphicsLayerReverse
        }
        Graphic {
            id: locationGraphicReverse
            symbol: simpleMarkerSymbolReverseLocation
        }
        Graphic {
            id: locationGraphicGeocode
            symbol: simpleMarkerSymbolLocation
        }
        Envelope {
            id: usExtent
            xMax:  8380686
            yMax: 3594113
            xMin:  8180686
            yMin: 3794113
            spatialReference: mainMap.spatialReference
        }
        onMouseClicked: {
            graphicsLayerReverse.removeAllGraphics();
            var graphic1 = locationGraphicReverse.clone();
            graphicsLayerReverse.addGraphic(graphic1);
             graphic1.geometry =  mouse.mapPoint
            locator.reverseGeocode(mouse.mapPoint, 500, mainMap.spatialReference);
        }
    }
    ServiceLocator {
        id: locator
        url: "http://maps.dhalahore.org/ArcGIS/rest/services/DHAMAP/AddressLocator/GeocodeServer"
        onGeocodeStatusChanged: {
            console.log("geocode address found")
            if(geocodeStatus === Enums.GeocodeStatusCompleted){
                 progressBar.visible = false;
                if(geocodeResults.length < 1){
                    showError("No address Found");
                }
                else {
                    for (var i = 0; i < geocodeResults.length; i++) {
                        var result = geocodeResults[i];
                        var graphic = locationGraphicGeocode.clone()
                        graphic.geometry = result.location;
                        graphicsLayerGeocode.addGraphic(graphic);
                    }
                    mainMap.zoomTo(graphic.geometry);
                }
            }else if (geocodeStatus === Enums.GeocodeStatusErrored) {
                progressBar.visible = false;
                showError(geocodeError.message + "\n No Address Found");
            }
        }
        onReverseGeocodeStatusChanged: {
            if (reverseGeocodeStatus === Enums.ReverseGeocodeStatusCompleted) {
                searchBox.descriptionTextVisibility = true;
                searchBox.descriptionTextInput = "Address: "
                var address = reverseGeocodeResult.addressFields["SingleKey"];
            } else if (reverseGeocodeStatus === Enums.ReverseGeocodeStatusErrored) {
                showError(reverseGeocodeError.message + "\nNo Address Found");
                searchBox.descriptionTextVisibility = false;
            }
        }
    }
    /*-----------------------------------------------------------------------------------------------------------------------
         Search button / box
         ---------------------------------------------------------------------------------------------------------------------*/
    SearchBox {
        id: searchBox
        anchors {
            left: parent.left
            top: parent.top
            margins: 20 * scaleFactor
        }
        onSearch: {           
            graphicsLayerGeocode.removeAllGraphics();
            var add = {"SingleKey": searchBox.searchTextInput}
            locator.geocode(add,"*",mainMap.spatialReference)
            progressBar.visible = true;
        }
        onClear: {
            mainMap.extent = usExtent;
            mainMap.mapRotation = 0;
            graphicsLayerGeocode.removeAllGraphics();
            graphicsLayerReverse.removeAllGraphics();
            searchBox.descriptionTextInput = "";
            searchBox.searchTextInput.focus = true;
            searchBox.descriptionTextVisibility = false;
            searchBox.searchTextInput = "";
        }
        Keys.onReturnPressed: {
            graphicsLayerGeocode.removeAllGraphics();
            var add = {"SingleKey": searchBox.searchTextInput}
            locator.geocode(add,"*",mainMap.spatialReference)
            progressBar.visible = true;
            Qt.inputMethod.hide();
        }
    }
    Row {
        anchors {
            horizontalCenter: parent.horizontalCenter
            bottom: mainMap.bottom
            bottomMargin: 5 * scaleFactor
        }
        ProgressBar {
            id: progressBar
            indeterminate: true
            visible: false
        }
    }
    MessageDialog {
        id: messageDialog
        title: "Error"
        icon: StandardIcon.Warning
        modality: Qt.WindowModal
        standardButtons: StandardButton.Ok
        text: errorMsg
    }
    Rectangle {
        id: rectangleBorder
        anchors.fill: parent
        color: "transparent"
        border {
            width: 0.5 * scaleFactor
            color: "black"
        }
    }
    function showError(errorString) {
        errorMsg = errorString;
        messageDialog.visible = true;
    }
}

View solution in original post

7 Replies
nakulmanocha
Esri Regular Contributor
Hi there,

There are couple of issues here, directly related to your Geocoding service. 

1) Your geocoding service is based on server 10.0 and hence only supports FindAddressCandidates. Therefore you should be using 
 locator.geocode() method to perform Geocoding. This method calls the FindAddressCandidates operation

2) Based on your service address field. It currently takes Single Address labelled as "SingleKey". Hence you should only use that as your Address field parameter.

I have added these suggestions in your code and pasted below for your reference.

I hope this helps.

Thank you.
Nakul





App
{
    id: app
    width: 800
    height: 532
    property double scaleFactor: AppFramework.displayScaleFactor
    property string errorMsg
    Map {
        id: mainMap
        anchors.fill: parent
        extent: usExtent
        focus: true
        ArcGISTiledMapServiceLayer {
            url: "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
        }
        SimpleMarkerSymbol {
            id: simpleMarkerSymbolLocation
            color: "red"
            style: Enums.SimpleMarkerSymbolStyleCross
            size: 10
        }
        SimpleMarkerSymbol {
            id: simpleMarkerSymbolReverseLocation
            color: "blue"
            style: Enums.SimpleMarkerSymbolStyleDiamond
            size: 10
        }
        GraphicsLayer {
            id: graphicsLayerGeocode
        }
        GraphicsLayer {
            id: graphicsLayerReverse
        }
        Graphic {
            id: locationGraphicReverse
            symbol: simpleMarkerSymbolReverseLocation
        }
        Graphic {
            id: locationGraphicGeocode
            symbol: simpleMarkerSymbolLocation
        }
        Envelope {
            id: usExtent
            xMax:  8380686
            yMax: 3594113
            xMin:  8180686
            yMin: 3794113
            spatialReference: mainMap.spatialReference
        }
        onMouseClicked: {
            graphicsLayerReverse.removeAllGraphics();
            var graphic1 = locationGraphicReverse.clone();
            graphicsLayerReverse.addGraphic(graphic1);
             graphic1.geometry =  mouse.mapPoint
            locator.reverseGeocode(mouse.mapPoint, 500, mainMap.spatialReference);
        }
    }
    ServiceLocator {
        id: locator
        url: "http://maps.dhalahore.org/ArcGIS/rest/services/DHAMAP/AddressLocator/GeocodeServer"
        onGeocodeStatusChanged: {
            console.log("geocode address found")
            if(geocodeStatus === Enums.GeocodeStatusCompleted){
                 progressBar.visible = false;
                if(geocodeResults.length < 1){
                    showError("No address Found");
                }
                else {
                    for (var i = 0; i < geocodeResults.length; i++) {
                        var result = geocodeResults[i];
                        var graphic = locationGraphicGeocode.clone()
                        graphic.geometry = result.location;
                        graphicsLayerGeocode.addGraphic(graphic);
                    }
                    mainMap.zoomTo(graphic.geometry);
                }
            }else if (geocodeStatus === Enums.GeocodeStatusErrored) {
                progressBar.visible = false;
                showError(geocodeError.message + "\n No Address Found");
            }
        }
        onReverseGeocodeStatusChanged: {
            if (reverseGeocodeStatus === Enums.ReverseGeocodeStatusCompleted) {
                searchBox.descriptionTextVisibility = true;
                searchBox.descriptionTextInput = "Address: "
                var address = reverseGeocodeResult.addressFields["SingleKey"];
            } else if (reverseGeocodeStatus === Enums.ReverseGeocodeStatusErrored) {
                showError(reverseGeocodeError.message + "\nNo Address Found");
                searchBox.descriptionTextVisibility = false;
            }
        }
    }
    /*-----------------------------------------------------------------------------------------------------------------------
         Search button / box
         ---------------------------------------------------------------------------------------------------------------------*/
    SearchBox {
        id: searchBox
        anchors {
            left: parent.left
            top: parent.top
            margins: 20 * scaleFactor
        }
        onSearch: {           
            graphicsLayerGeocode.removeAllGraphics();
            var add = {"SingleKey": searchBox.searchTextInput}
            locator.geocode(add,"*",mainMap.spatialReference)
            progressBar.visible = true;
        }
        onClear: {
            mainMap.extent = usExtent;
            mainMap.mapRotation = 0;
            graphicsLayerGeocode.removeAllGraphics();
            graphicsLayerReverse.removeAllGraphics();
            searchBox.descriptionTextInput = "";
            searchBox.searchTextInput.focus = true;
            searchBox.descriptionTextVisibility = false;
            searchBox.searchTextInput = "";
        }
        Keys.onReturnPressed: {
            graphicsLayerGeocode.removeAllGraphics();
            var add = {"SingleKey": searchBox.searchTextInput}
            locator.geocode(add,"*",mainMap.spatialReference)
            progressBar.visible = true;
            Qt.inputMethod.hide();
        }
    }
    Row {
        anchors {
            horizontalCenter: parent.horizontalCenter
            bottom: mainMap.bottom
            bottomMargin: 5 * scaleFactor
        }
        ProgressBar {
            id: progressBar
            indeterminate: true
            visible: false
        }
    }
    MessageDialog {
        id: messageDialog
        title: "Error"
        icon: StandardIcon.Warning
        modality: Qt.WindowModal
        standardButtons: StandardButton.Ok
        text: errorMsg
    }
    Rectangle {
        id: rectangleBorder
        anchors.fill: parent
        color: "transparent"
        border {
            width: 0.5 * scaleFactor
            color: "black"
        }
    }
    function showError(errorString) {
        errorMsg = errorString;
        messageDialog.visible = true;
    }
}
MuhammadAfzal
New Contributor

I am very Grateful Nakul Manocha.

It's working perfect.

One question please "On performing search it's find all  addresses (E.g When I search 5 G 82 ,it's highlight 5 G 82,5 G 8/2 and 5 J 82) but I need when i write specific address it's only find that particular address.

It would be greatly appreciated.

 

Cheers,

 

"Tasadduq Hussain"  

0 Kudos
nakulmanocha
Esri Regular Contributor

If you want only one address then you check for the score condition within the results and don't include if the score is not 100. I see based on your Geocode service I am getting lots of results with score >90. Hence I would recommend (

result.score <100) then it will include only one record.

http://maps.dhalahore.org/ArcGIS/rest/services/DHAMAP/AddressLocator/GeocodeServer/findAddressCandid... 

else {
                    for (var i = 0; i < geocodeResults.length; i++) {
                        var result = geocodeResults[i];
                        if (result.score <100)
                            return;
                        var graphic = locationGraphicGeocode.clone()
                        graphic.geometry = result.location;
                        graphicsLayerGeocode.addGraphic(graphic);
                    }

Hope this helps,

Nakul

AbdulMannan
New Contributor II

I am very Grateful Nakul Manocha.

It's great idea.

 I will putt condition on my matching score based on my Geocode Service.

I will replay you after putting condition..

Again I am very thankful to you.

 

Cheers,

 

"Tasadduq Hussain"

0 Kudos
AbdulMannan
New Contributor II

Very Grateful Nakul Manocha.

 

 I  putt condition

if (result.score <100)
return;

I working perfect and find only one address but it does not Zoom to that particular address.

Please see the screen shot.

 

Highlight Adress But does not Zoom

It would be greatly appreciated.

Cheers,

 "Tasadduq Hussain"

0 Kudos
nakulmanocha
Esri Regular Contributor

That is expected as the single point geometry doesn't have an extent ( as min x,y and max x,y has same values). What you would have to do is to create a virtual extent around the point geometry and then zoom to that extent. 

Another way is to create a buffer geometry (invisible- don't add it as graphic) around that point and then zoom to that buffer geometry.

Nakul

AbdulMannan
New Contributor II

I am very Grateful Nakul Manocha.

 

I create Locator with Minimum Match/Candidate Score 100.

Now,it's working perfect and find only one address and also Zoom to that particular address.

Again I am very thankful to you.

 Cheers,

"Tasadduq Hussain"

0 Kudos