/// <summary>Executes a search and creates a map that displays the search results.</summary>
/// <param name="sender">The sender</param>
/// <param name="e">Event arguments</param>
protected void Button_SearchWithMap_Click(object sender, EventArgs e)
{
// Clear our results output
this.Div_SearchResults.InnerHtml = "";
// Execute a search
SearchResponse searchResponse = this.ExecuteSearch();
bool foundSearchResult = false;
// Create a map, specify search results with the map request so pushpins will be rendered on the map
if (searchResponse != null)
{
// Create a new MapUriRequest
VEImageryService.MapUriRequest mapUriRequest = new MapUriRequest();
// Create a new Credential object and provide the token
mapUriRequest.Credentials = new VEImageryService.Credentials();
mapUriRequest.Credentials.Token = Utils.Token(Request.UserHostAddress);
//Set the size of the map requested to the size of the image control
mapUriRequest.Options = new MapUriOptions
{
ImageSize = new VEImageryService.SizeOfint
{
Height = Convert.ToInt32(this.Image_Map.Height.Value),
Width = Convert.ToInt32(this.Image_Map.Width.Value)
}
};
// Create a new pushpin list
List<VEImageryService.Pushpin> pushpinList = new List<Pushpin>();
// Add each of the search results to the pushpin list
foreach (SearchResultSet searchResultSet in searchResponse.ResultSets)
{
int businessCounter = 0;
foreach (BusinessSearchResult busniessSearchResult in searchResultSet.Results)
{
foundSearchResult = true;
// Write the search result data to the info box
this.WriteInfo(++businessCounter + ") <b>" + busniessSearchResult.Name + "</b>");
this.WriteInfo(" " + busniessSearchResult.Address.FormattedAddress);
string website = "";
if (busniessSearchResult.Website != null)
website = "<a href='" + busniessSearchResult.Website.ToString() + "'>Website</a>";
this.WriteInfo(" " + busniessSearchResult.PhoneNumber + " " + website);
this.WriteInfo("");
// Build out the pushpin and add it to the list
Pushpin pushpin = new Pushpin();
// push pin labels only support 2 characters
pushpin.Label = businessCounter.ToString(); // += "asdf";
// Just get the first location returned
if (busniessSearchResult.LocationData.Locations.Length > 0)
{
//this.WriteInfo("Location: " + busniessSearchResult.LocationData.Locations[0].Latitude + "," + busniessSearchResult.LocationData.Locations[0].Longitude);
pushpin.Location = new VEImageryService.Location();
pushpin.Location.Latitude = busniessSearchResult.LocationData.Locations[0].Latitude;
pushpin.Location.Longitude = busniessSearchResult.LocationData.Locations[0].Longitude;
}
pushpinList.Add(pushpin);
}
}
// Add the pushpin list (as an array) to the MapUriRequest
mapUriRequest.Pushpins = pushpinList.ToArray();
ImageryServiceClient imageryServiceClient = new ImageryServiceClient();
// Get the map and render it on the UI
MapUriResponse mapUriResponse = imageryServiceClient.GetMapUri(mapUriRequest);
this.Image_Map.ImageUrl = mapUriResponse.Uri;
this.Image_Map.Visible = true;
}
if (foundSearchResult == false)
this.WriteInfo("No search results for query");
}