The street line of an address.
This example requests title, description, and address information from the PhoneBookSourceType and displays the information in a Console Window. The request for address information and the AddressLine property return code are featured in bold, below.
try
{
MSNSearchService s = new MSNSearchService();
SearchRequest searchRequest = new SearchRequest();
int arraySize = 1;
SourceRequest[] sr = new SourceRequest[arraySize];
sr[0] = new SourceRequest();
sr[0].Source = SourceType.PhoneBook;
sr[0].ResultFields = ResultFieldMask.Title | ResultFieldMask.Description | ResultFieldMask.Address;
searchRequest.Query = "coffee";
searchRequest.Requests = sr;
// Enter the Application ID, in double quotation marks, supplied by the
// Developer Provisioning System, as the value of the AppID on the SearchRequest.
searchRequest.AppID = "YOUR_APP_ID_GOES_HERE";
searchRequest.CultureInfo = "en-US";
// Set Location to Seattle Tacoma International Airport, Washington, USA and accept
// a default radius value of 5.0 Miles. You can modify the Location, using decimal values
// for latitude and longitude, to return addresses in other supported markets.
searchRequest.Location = new Location();
double latitude = 47.422433;
double longitude = -122.305833;
searchRequest.Location.Latitude = latitude;
searchRequest.Location.Longitude = longitude;
SearchResponse searchResponse;
searchResponse = s.Search(searchRequest);
foreach (SourceResponse sourceResponse in searchResponse.Responses)
{
Result[] sourceResults = sourceResponse.Results;
if (searchResponse.Responses[0].Total > 0)
{
Console.WriteLine(sourceResponse.Source.ToString() + " - Total Results: " + sourceResponse.Total.ToString());
Console.WriteLine();
}
foreach (Result sourceResult in sourceResults)
{
if ((sourceResult.Title != null) && (sourceResult.Title != String.Empty))
Console.WriteLine("Title: " + sourceResult.Title);
if ((sourceResult.Description != null) && (sourceResult.Description != String.Empty))
Console.WriteLine("Description: " + sourceResult.Description);
if (sourceResult.Address != null)
{
if ((sourceResult.Address.AddressLine != null) && (sourceResult.Address.AddressLine != String.Empty)) Console.WriteLine("AddressLine: " + sourceResult.Address.AddressLine);
if ((sourceResult.Address.CountryRegion != null) && (sourceResult.Address.CountryRegion != String.Empty))
Console.WriteLine("CountryRegion: " + sourceResult.Address.CountryRegion);
if ((sourceResult.Address.PostalCode != null) && (sourceResult.Address.PostalCode != String.Empty))
Console.WriteLine("PostalCode: " + sourceResult.Address.PostalCode);
if ((sourceResult.Address.PrimaryCity != null) && (sourceResult.Address.PrimaryCity != String.Empty))
Console.WriteLine("PrimaryCity: " + sourceResult.Address.PrimaryCity);
if ((sourceResult.Address.SecondaryCity != null) && (sourceResult.Address.SecondaryCity != String.Empty))
Console.WriteLine("SecondaryCity: " + sourceResult.Address.SecondaryCity);
if ((sourceResult.Address.Subdivision != null) && (sourceResult.Address.Subdivision != String.Empty))
Console.WriteLine("Subdivision: " + sourceResult.Address.Subdivision);
}
Console.WriteLine("*****************************************************");
}
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
}
catch (System.Web.Services.Protocols.SoapException fault)
{
Console.WriteLine(fault.Detail.InnerText.ToString());
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
catch (System.Net.WebException webx)
{
Console.WriteLine(webx.ToString());
}
The following sample output shows results of this query. Note that, if you run the same query, your output is likely to be different due to the fact that you ran your query at a later time.
PhoneBook - Total Results: 1012
Title: Sip & Shine Espresso
Description: (206) 878-0716 - 21000 International Blvd, Seatac, WA
AddressLine: 21000 International Blvd
CountryRegion: US
PrimaryCity: Seatac
Subdivision: WA
*****************************************************
Title: Cafe Valle
Description: (206) 824-9424 - 21031 International Blvd, Seatac, WA
AddressLine: 21031 International Blvd
CountryRegion: US
PrimaryCity: Seatac
Subdivision: WA
*****************************************************
Title: Leah's Lattes
Description: (206) 870-4693 - 19245 Des Moines Memorial Dr, Seatac, WA
AddressLine: 19245 Des Moines Memorial Dr
CountryRegion: US
PrimaryCity: Seatac
Subdivision: WA
*****************************************************
Title: Starbucks
Description: (206) 824-2737 - 21401 International Blvd, Des Moines, WA
AddressLine: 21401 International Blvd
CountryRegion: US
PrimaryCity: Des Moines
Subdivision: WA
*****************************************************
Title: Celestial Expresso
Description: (206) 824-9454 - 20738 1st Pl S, Des Moines, WA
AddressLine: 20738 1st Pl S
CountryRegion: US
PrimaryCity: Des Moines
Subdivision: WA
*****************************************************
Title: North Hill Espresso
Description: (206) 824-9454 - 20738 1st S, Des Moines, WA
AddressLine: 20738 1st S
CountryRegion: US
PrimaryCity: Des Moines
Subdivision: WA
*****************************************************
Title: Sisters Espresso
Description: (206) 244-2233 - 18205 Des Moines Memorial Dr, Seatac, WA
AddressLine: 18205 Des Moines Memorial Dr
CountryRegion: US
PrimaryCity: Seatac
Subdivision: WA
*****************************************************
Title: Cafe Debra At Marine View
Description: (206) 824-6672 - 21904 Marine View Dr S, Des Moines, WA
AddressLine: 21904 Marine View Dr S
CountryRegion: US
PrimaryCity: Des Moines
Subdivision: WA
*****************************************************
Title: Diva Espresso
Description: (206) 652-5797 - 17801 International Blvd, Seatac, WA
AddressLine: 17801 International Blvd
CountryRegion: US
PrimaryCity: Seatac
Subdivision: WA
*****************************************************
Title: Concessions International Inc
Description: (206) 431-1232 - 17801 International Blvd # 311, Seatac, WA
AddressLine: 17801 International Blvd # 311
CountryRegion: US
PrimaryCity: Seatac
Subdivision: WA
*****************************************************
Press any key to exit.