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;
}
}