使用bing map API,我可以进行服务器端调用并获得给定城市的lat / long吗?

时间:2010-05-14 19:50:54

标签: c# asp.net bing-maps

使用bing map API,我可以进行服务器端调用并获得给定城市的lat / long吗?

我可以使用JavaScript在客户端执行此操作,但在这种情况下我需要更强大的功能并希望使用服务器端。

1 个答案:

答案 0 :(得分:0)

发布此信息,以便更容易找到每个人的答案:

使用Bing Maps SOAP Services API(http://msdn.microsoft.com/en-us/library/cc980922.aspx)。它是一个公共Web服务,实现大多数Bing Maps API并提供静态映射(抱歉,没有来自用户的交互)。从提供的Microsoft SDK(稍加修改:将服务引用添加到项目后,运行此代码:

私有GeocodeResponse GeocodeAddress(字符串地址)         {             GeocodeRequest geocodeRequest = new GeocodeRequest();

        // Set the credentials using a valid Bing Maps key
        geocodeRequest.Credentials = new GeocodeService.Credentials();
        geocodeRequest.Credentials.ApplicationId = BingMapsAPIKey;

        // Set the full address query
        geocodeRequest.Query = address;

        // Set the options to only return high confidence results 
        ConfidenceFilter[] filters = new ConfidenceFilter[1];
        filters[0] = new ConfidenceFilter();
        filters[0].MinimumConfidence = GeocodeService.Confidence.High;

        // Add the filters to the options
        GeocodeOptions geocodeOptions = new GeocodeOptions();
        geocodeOptions.Filters = filters;
        geocodeRequest.Options = geocodeOptions;

        // Make the geocode request
        GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
        GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);

        return geocodeResponse;
}

您可以使用以下代码片段检查返回值:

result.Locations[0].Latitude.ToString();
result.Locations[0].Longitude.ToString();