Click to Rate and Give Feedback
MSDN
MSDN Library
Online Services
Bing Services
Bing API
API Reference
Location Class
 Location.Longitude Property (Search...
Collapse All/Expand All Collapse All
Location.Longitude Property (Search)

The Longitude component of the Location.

public double Longitude { get; set; }

Valid input values for Longitude range from -180 to 180. For accurate results, input values must be converted to the decimal representation of the Longitude value. Output values are returned in decimal format for results of SourceType.PhoneBook only.

Lines of longitude, also known as meridians, run between the North and South Poles. They measure east-west position in degrees, minutes, and seconds. The Prime Meridian, which runs through Greenwich, England, is assigned the value of 0 degrees. Meridians to the west of the Prime Meridian are assigned negative values, and those to the east are assigned positive values. For example, the longitude of Seattle, Washington is 122° 19' 51.04" W, which converts to the (negative) decimal value of -122.328567.

This example requests title, description, and location information from the PhoneBook SourceType and displays the information in a Console Window. The request for location information and the Longitude 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.Location;

    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 the center of Seattle, Washington, USA and set the
    // radius value to 25.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.603828;
    double longitude = -122.328567;
    double radius = 25.0;
    searchRequest.Location.Latitude = latitude;
    searchRequest.Location.Longitude = longitude;
    searchRequest.Location.Radius = radius;

    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.Location != null)
            {
                Console.WriteLine("Latitude: " + sourceResult.Location.Latitude.ToString());
                Console.WriteLine("Longitude: " + sourceResult.Location.Longitude.ToString());
                // Radius always returns '5,' regardless of the value requested.
                Console.WriteLine("Radius: " + sourceResult.Location.Radius.ToString());
            }
            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: 11103

Title: Tully's Coffee

Description: (206) 682-6575 - 701 5th Ave, Seattle, WA

Latitude: 47.604359

Longitude: -122.329779

Radius: 5

*****************************************************

Title: Starbucks Coffee

Description: (206) 447-9934 - 701 5th Ave, Seattle, WA

Latitude: 47.604359

Longitude: -122.329779

Radius: 5

*****************************************************

Title: Walters Waffles

Description: (206) 622-8020 - 701 5th Ave Ste 3600, Seattle, WA

Latitude: 47.604359

Longitude: -122.329779

Radius: 5

*****************************************************

Title: Starbucks

Description: (206) 622-5789 - 700 5th Ave # 4, Seattle, WA

Latitude: 47.604402

Longitude: -122.329798

Radius: 5

*****************************************************

Title: 4th Avenue Caffe

Description: (206) 340-9035 - 500 4th Ave, Seattle, WA

Latitude: 47.602469

Longitude: -122.329599

Radius: 5

*****************************************************

Title: Starbucks

Description: (206) 447-9934 - 701 4th Ave, Seattle, WA

Latitude: 47.604007

Longitude: -122.330905

Radius: 5

*****************************************************

Title: M & M Assoc

Description: (206) 625-3253 - 800 5th Ave, Seattle, WA

Latitude: 47.60506

Longitude: -122.33046

Radius: 5

*****************************************************

Title: Pioneer Mart

Description: (206) 903-6324 - 609 3rd Ave, Seattle, WA

Latitude: 47.602865

Longitude: -122.331462

Radius: 5

*****************************************************

Title: All City Coffee

Description: (206) 652-8331 - 125 Prefontaine Pl S, Seattle, WA

Latitude: 47.60146

Longitude: -122.329689

Radius: 5

*****************************************************

Title: Pegasus Coffee Bar

Description: (206) 682-3113 - 711 3rd Ave # 331, Seattle, WA

Latitude: 47.603602

Longitude: -122.332252

Radius: 5

*****************************************************

Press any key to exit.

© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker