﻿// Use the Map Control to find and geocode the location from where we are searching from
function GetStoresNearLocation() {
    map.DeleteAllShapes();
    var sLocationText = document.getElementById("LocationText").value;
    try {
        //First, find and get the coordinates for the Location
        map.Find(null,           //what
             sLocationText,          //where
             null,              //findType
             null,              //shapeLayer
             null,              //startIndex
             10,                //numberOfResults
             true,              //showResults
             true,              //createResults
             true,             //useDefaultDisambiguation
             null,              //setBestMapView
             GetStoresFindCallback); //callback   
    }
    catch (Err) {
        alert(Err.description);
    }
}

//Once the location has been geocoded, we can pass it to the Web handler
function GetStoresFindCallback(layer, resultsArray, places, hasMore, veErrorMessage) {
    //get the first location
    var place = places[0];
    //alert(place.Name + ' : ' + place.LatLong); 
    var geoRssLayer = new VEShapeLayer();
    veLayerSpec = new VEShapeSourceSpecification(
        VEDataType.GeoRSS,
        "GeoRSSHandler.ashx?location=" + place.LatLong +
            "&maxdistance=" + document.getElementById("MaxDistance").value,
        geoRssLayer);
    map.ImportShapeLayerData(veLayerSpec, SucceededSLCallback, 1);
}


function SucceededSLCallback(result) {
    map.SetZoomLevel(8);
    var resultsBox = document.getElementById("txtResults");
    resultsBox.value = result.GetShapeCount() + " stores found.";
}

