Sie sind auf Seite 1von 155

Contents

Bing Spatial Data Services Getting Started with the Spatial Data Services Bing Spatial Data Services API Reference Dataflow and Data Source Job Requirements Geocode Dataflow API Create a Geocode Job and Upload Data Get Status of a Geocode Job Download Geocode Job Results Geocode Dataflow Response Description Geocode Dataflow Walkthrough Geocode Dataflow Sample Code Geocode Dataflow Data Schema Geocode Dataflow Sample Input and Output Data Entity Types Data Source Management API Load Data Source Dataflow Create a Load Data Source Job and Input Entity Data Get Status of a Load Data Source Job Load Data Source Dataflow Response Description Load Data Source Data Schema and Sample Input Get Data Source Information Delete a Data Source Query API Query by Area Query by Property Query by ID Query Options Query Response Description Status Codes and Errors

2

3

4

5

5

7

13

17

21

28

35

45

53

65

77

78

79

88

95

102

108

115

117

118

132

139

149

152

154

Bing Spatial Data Services

The Bing™ Spatial Data Services Application Programming Interface (API) provides a Representational State Transfer (REST) interface that can geocode, store and query spatial data. This simple REST interface accomplishes tasks by setting parameters in a URL and then submitting the URL as an HTTP request. The HTTP response returns the results of the request.

With the Bing Spatial Data Services, you can:



Geocode and Reverse-Geocode large numbers of locations with the Geocode Dataflow API.



Store and query sets of properties for an entity type that you define, such as set of retail stores or restaurants. The Load Data Source Dataflow creates a data store called a data source for an entity type that you define and uploads entity data to that data source. The data schema and input data you provide can be specified by using XML or as a set of values separated by commas, tabs or pipe (|) characters. After a data source is created, use the URLs in the Query API to make queries. You can Query by Area to search for entities in a particular area. You can also Query by Property and Query by ID.

You need Bing Maps Keys to use the Bing Spatial Data Services. For more information about how to get Bing Maps Keys, see Getting a Bing Maps Key.

If you are reading this SDK online, you can download the Bing Spatial Data Services SDK CHM file or PDF file for offline viewing.

The Bing Spatial Data Services documentation contains reference topics for the following API:

Geocode Dataflow API

Use this API to geocode a set of spatial data.

Data Source Management API

Use this API to create, update, and delete data sources. A data source is a type of data store that stores entities of a user-defined entity type.

Query API

Use this API to query a data source.

Transaction accounting is provided when you use the Bing Spatial Data Services. For more information about billable and non-billable transactions for the Bing Spatial Data Services, see Usage Transactions.

In this Section

Getting Started with the Spatial Data Services

Provides information to help you get started with the Bing Spatial Data Services.

Bing Spatial Data Services API Reference

Includes detailed descriptions and examples for the Bing Spatial Data Services API.

Getting Started with the Spatial Data Services

The Bing Spatial Data Services provide REST APIs that work with large sets of spatial data. With these APIs you can geocode spatial data and you can store data that has a spatial component in data sources that you can query.

See the links in the How to: sections below to find out more information.

Get started by signing up for a Bing Maps Developer Account

To use the Bing Spatial Data Services, you must have a Bing Maps Developer Account. Once you have a Bing Maps Developer Account, you can create Bing Maps Key to use with the Bing Spatial Data Services. For information about getting a Bing Maps Developer Account and Bing Maps Keys, see Getting a Bing Maps Key.

How to: Geocode and reverse-geocode spatial data

Use the Geocode Dataflow API to create dataflow jobs that geocode and reverse-geocode large sets of data. For more information, see Geocode Dataflow API. For an example of the complete process, see the Geocode Dataflow Walkthrough

How to: Create a data source

Use the Load Data Source Dataflow to create a new data source.

If you are an enterprise customer, you can use the Bing Maps Account Center (https://www.bingmapsportal.com) to geocode and publish data to a new data source. For more information, see Geocode and Publish Entity Data to a Data Source.

How to: Update a data source

Use the Load Data Source Dataflow to update an existing data source.

If you are an enterprise customer, you can use the Bing Maps Account Center (https://www.bingmapsportal.com) to geocode and publish data to an existing data source. For more information, see Geocode and Publish Entity Data to a Data Source.

How to: Delete a data source

Use the Delete a Data Source API to delete a data source.

How to: Get information about data sources

Use the Get Data Source Information API to get information about a data source such as the entity type and properties that it stores. You can also request information about all of the data sources that belong to a Bing Maps Developer Account.

How to: Query a data source

Use the Query API to query for entities in a data source.

Sample Data Source: FourthCoffeeSample

FourthCoffeeSample is the name of a sample data source that you can use to learn about the Query API. You can also use it to learn how to get information about a data source by using the Data Source Management API. The FourthCoffeeSample data source contains an entity type named FourthCoffeeShops. You can use any Bing Maps Key to query this data source. All Query API transactions are billable transactions including queries to the FourthCoffeeSample data source. Therefore, you may want to create an evaluation account to use with this data source. For more information about how to create an evaluation account, see Getting a Bing Maps Key.

To find out the entity properties for this datasource, use the following URL by replacing YourBingMapsKey with any Bing Maps Key.

http://spatial.virtualearth.net/REST/v1/data/20181f26d9e94c81acdf9496133d4f23/FourthCoffe

eSample/$metadata?key=YourBingMapsKey

To query this data source, use the following base URL. See the Query API for URL templates and examples.

http://spatial.virtualearth.net/REST/v1/data/20181f26d9e94c81acdf9496133d4f23/FourthCoffe

eSample/FourthCoffeeShops

Transaction Accounting

Transactions are counted for each Bing Spatial Data Services request sent with a valid Bing Maps Key. For information about billable and non-billable transactions for the Bing Spatial Data Services and how to view them, see Viewing Bing Maps Usage Reports.

Bing Spatial Data Services API Reference

This section contains reference documentation for the Bing Spatial Data Services.

In this section

Dataflow and Data Source Job Requirements

Defines limits on the total number of dataflow and data source jobs, such as the number of jobs that can be in process at the same time.

Geocode Dataflow API

Describes the API that geocodes sets of spatial data.

Data Source Management API

Describes the API that creates and manages data sources.

Query API

Describes the API that queries a data source. You can query for entities in a given area or search by entity property or ID.

Status Codes and Errors

Describes the HTTP errors that can occur when you use the Bing Spatial Data Services APIs.

Dataflow and Data Source Job Requirements

Services APIs. Dataflow and Data Source Job Requirements Dataflow jobs and Data source jobs have the

Dataflow jobs and Data source jobs have the following limits:



You can have a total of 10 dataflow and data source jobs in process at the same time for a specified Bing Maps Developer Account.



You can run a total of 50 dataflow and data source jobs in a 24 hour period for a Bing Maps Developer Account.

These totals include Geocode Dataflow jobs, Load Data Source Dataflow jobs, and Delete Data Source jobs and apply to all jobs that have a status of “Pending”. Dataflow and data source jobs have a status of “Pending” until they have completed processing at which time the status is set to “Complete”.

A job is associated with a Bing Maps Developer Account if it is using a Bing Maps Key that is from that account. Therefore, if you created two jobs using two different Bing Maps Keys from the same account, both jobs count towards the total number of jobs in process.

Geocode Dataflow API

The Geocode Dataflow API is a component of the Bing Spatial Data Services. You can use the Geocode Dataflow API to geocode and reverse-geocode large sets of spatial data.

The Geocode Dataflow API specifies two URL templates. The Create a Geocode Job and Upload Data URL uploads your data and creates a geocode job. The Get Status of a Geocode Job URL gets the status of a geocode job. The same templates are used to both geocode and reverse- geocode spatial data. You can combine data to geocode and data to reverse geocode and process the combined data with one geocode job.

When your job has completed, the response to the Get Status of a Geocode Job URL provides URLs to use to download data. Different URLs are provided for data that was processed successfully and for data that encountered errors during processing. For more information, see Download Geocode Job Results.

The spatial data you upload can be in XML format, or it can be provided as sets of values that use commas, tabs, or pipe (|) characters to separate the values. For more information, see Geocode Dataflow Data Schema and Geocode Dataflow Sample Input and Output Data. The data that you download from a geocode job is provided in the same format as the data that you upload.

For an overview of the Geocode Dataflow process, see Geocode Dataflow Walkthrough. For a complete code sample, see Geocode Dataflow Sample Code.

a complete code sample, see Geocode Dataflow Sample Code . The data you upload with a

The data you upload with a Geocode Dataflow job must meet the following requirements:



The size of the data must be no more than 300 MB. If the data is compressed, the size of the uncompressed data must be no more than 300 MB. Input data must use UTF-8 encoding.



The data must contain no more than 200,000 location entities.

You can download geocode results for up to 14 calendar days after a geocode job completes.

There are limits on the number of dataflow and dataflow jobs that you can create. For more information, see Dataflow and Data Source Job Requirements.

In this Section

Create a Geocode Job and Upload Data

Describes how to create a job to geocode and reverse-geocode the data.

Get Status of a Geocode Job

Describes how to get the status of a geocode job.

Download Geocode Job Results

Describes how to download geocoded results.

Geocode Dataflow Response Description

Describes the information returned in the HTTP responses.

Geocode Dataflow Walkthrough

Provides a detailed overview of how to use the Geocode Dataflow.

Geocode Dataflow Sample Code

Provides complete sample code that uses the Geocode Dataflow to geocode data.

Geocode Dataflow Data Schema

Describes the data schema for the input data and the geocoded results.

Geocode Dataflow Sample Input and Output Data

Shows examples of all types of accepted input formats. This includes XML examples and examples of sets of values separated by pipe (|), comma, or tab characters

Entity Types

Provides a list of supported entity types.

Create a Geocode Job and Upload Data

Use the following URL to upload a set of spatial data and to create a job to geocode and reverse- geocode the data.

Supported HTTP Methods

POST

URL template

geocode the data. Supported HTTP Methods POST URL template This template supports both HTTP and HTTPS

This template supports both HTTP and HTTPS protocols. URLs in the response use HTTPS protocol.

Upload locations and points and create a geocode job.

You can upload up to 300 MB of data for each job, and the number of location entities cannot be larger than 200,000. If your data is compressed, the size of the uncompressed data must be no more than 300 MB. Input data must use UTF-8 encoding.

The data that you upload can contain both data to geocode and data to reverse geocode. The geocode process detects the type of data for each entry and performs the appropriate action.

There are limits on the number of dataflow and data source jobs that you can create. For more information, see Dataflow and Data Source Job Requirements.

http://spatial.virtualearth.net/REST/v1/Dataflows/Geocode?description=description&input=i

nput&output=output&dataLocation=dataLocation&key=BingMapsKey

Template Parameters

dataLocation &key= BingMapsKey Template Parameters Parameter names and values are not case-sensitive except for

Parameter names and values are not case-sensitive except for the key parameter value.

Parameter

Alia

Description

Values

 

s

   

dataLocati

 

Optional. Specifies the location of the data to download.

A Windows Azure™ Blob Service location that contains the data to process. The data must be in XML format. The Blob Service uses the following URL formats:

http://account-name.blob.core.windows.net/myDataFile

on

https:// account-name .blob.core.windows.net/ myDataFile

https://account-name.blob.core.windows.net/myDataFile

You must

For more information, see Addressing Blob Service Requests.

set the

dataLocati

Before you make your request to start the dataflow job, make sure that the Blob Service URL is available publicly or shared with a signature key. If the URL is shared with

on

parameter

Parameter

Alia

Description

 

Values

 

s

   
   

to the

a

signature key, it must be encoded. For more

location of

the data

or include

The following content types are supported for data that is retrieved from an HTTP server.

the data

to process

 

in the

HTTP

 application/xml

 text/xml

request. If

 text/plain

you do

 application/octet-stream

both, the

Example:

URL

dataLocation=http://myServer.myDomain.com/spatialDat

returns an

aSource

error.

description

 

Optional. A description of the geocode dataflow.

A

user-defined string that identifies the dataflow.

Example: description=Seattle Stores Geocode

input

 

Required. The format of the input data file.

One of the following values:

 xml

 



csv



tab

 pipe

For more information about input files for a Geocode Dataflow, see Geocode Dataflow Data Schema.

Example: input=csv

key

 

Required. A Bing Maps Key to use for the geocode job.

A

Bing Maps Key obtained from the Bing Maps Account

output

o

Optional. The output format for the response.

One of the following values:

json [default]

 

xml

 

Example: output=xml

Input

This URL supports the following input formats. For examples, see Geocode Dataflow Sample Input and Output Data.

When you create the HTTP request to upload data and create a geocode job, you must post the input data in the body of the request or set the dataLocation parameter to a URL where your data can be retrieved. You must also set the content type in the request to one of the following values, depending on the format of the input data.



XML (application/xml)



Comma-delimited values (text/plain)



Tab-delimited values (text/plain)



Pipe-delimited values (text/plain)



Binary (application/octet-stream)

Examples

This example creates a geocode job for spatial data that is provided in an xml format.

http://spatial.virtualearth.net/REST/v1/Dataflows/Geocode?input=xml&key=BingMapsKey

This example creates a geocode job for spatial data that is provided in an xml format and assigns a description “My dataflow” to the job.

http://spatial.virtualearth.net/REST/v1/Dataflows/Geocode?input=xml&description=My

dataflow&key=BingMapsKey

Response

The response to this URL contains a representation of the geocode dataflow job instance.

This URL supports the following response formats.



JSON (application/json)



XML (application/xml)

For information about the response, see Geocode Dataflow Response Description.

Sample Code

The following code shows how to create a job to geocode spatial data. The data you want to geocode is uploaded as part of the job creation process. This code is part of a complete Geocode Dataflow code sample. To view the complete code sample, see Geocode Dataflow Sample Code. You may also want to read the Geocode Dataflow Walkthrough to get a step-by-step description of how to use the Geocode Dataflow. The walkthrough includes example URLs and HTTP responses.

//Creates a geocode dataflow job and uploads spatial data to process.

//Parameters:

//

dataFilePath: The path to the file that contains the spatial data to

geocode.

//

dataFormat: The format of the input data. Possible values are xml, csv, tab

and pipe.

//

key: The Bing Maps Key to use for this job. The same key is used to get job

status and download results.

//

description: Text that is used to describe the geocode dataflow job.

//Return value : A URL that defines the location of the geocode dataflow job that was created.

static string CreateJob(string dataFilePath, string dataFormat, string key, string description)

{

//Define parameters for the HTTP request

//

// The 'Content-Type' header of the HTTP Request must be "text/plain" or "application/xml"

// depending on the input data format.

//

string contentType = "text/plain";

if (dataFormat.Equals("xml", StringComparison.OrdinalIgnoreCase))

contentType = "application/xml";

StringBuilder queryStringBuilder = new StringBuilder();

//

// The 'input'(input format) and 'key' (Bing Maps Key) parameters are

required.

//

queryStringBuilder.Append("input=").Append(Uri.EscapeUriString(dataFormat));

queryStringBuilder.Append("&");

queryStringBuilder.Append("key=").Append(Uri.EscapeUriString(key));

if (!String.IsNullOrEmpty(description))

{

//

// The 'description' parameter is optional.

//

queryStringBuilder.Append("&");

queryStringBuilder.Append("description=").Append(Uri.EscapeUriString(description));

}

//Build the HTTP URI that will upload and create the geocode dataflow job

UriBuilder uriBuilder = new UriBuilder("http://spatial.virtualearth.net");

uriBuilder.Path = "/REST/v1/dataflows/geocode";

uriBuilder.Query = queryStringBuilder.ToString();

//Include the data to geocode in the HTTP request

using (FileStream dataStream = File.OpenRead(dataFilePath))

{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriBuilder.Uri);

//

// The HTTP method must be 'POST'.

//

request.Method = "POST";

request.ContentType = contentType;

using (Stream requestStream = request.GetRequestStream())

{

byte[] buffer = new byte[16384];

int bytesRead = dataStream.Read(buffer, 0, buffer.Length);

while (bytesRead > 0)

{

 

requestStream.Write(buffer, 0, bytesRead);

bytesRead = dataStream.Read(buffer, 0, buffer.Length);

}

}

//Submit the HTTP request and check if the job was created successfully.

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())

{

//

// If the job was created successfully, the status code should be

// 201 (Created) and the 'Location' header should contain a URL

// that defines the location of the new dataflow job. You use this

// URL with the Bing Maps Key to query the status of your job.

//

if (response.StatusCode != HttpStatusCode.Created)

throw new Exception ("An HTTP error status code was encountered when creating the geocode job.");

string dataflowJobLocation = response.GetResponseHeader("Location");

if (String.IsNullOrEmpty(dataflowJobLocation))

throw new Exception ("The 'Location' header is missing from the HTTP response when creating a goecode job.");

return dataflowJobLocation;

}

}

}

HTTP Status Codes

return dataflowJobLocation; } } } HTTP Status Codes For more details about these HTTP status codes,

For more details about these HTTP status codes, see Status Codes and Errors.

When the request is successful, the following HTTP status code is returned.  201 When the request is not successful, the response returns one of the following errors.  400  500



503

 503 The response may contain a 503 HTTP status error code when the number of

The response may contain a 503 HTTP status error code when the number of pending geocode dataflow jobs is exceeded. The maximum number of pending geocode dataflow jobs that can be associated with a Bing Maps Key is 10.

Get Status of a Geocode Job

Use the following URL to get the status of a geocode job.

Supported HTTP Methods

GET

URL template

of a geocode job. Supported HTTP Methods GET URL template This template supports both HTTP and

This template supports both HTTP and HTTPS protocols. URLs in the response use HTTPS protocol.

Get status information for a geocode job.

The Bing Maps Key that you specify must be the same Bing Maps Key that you used to create the job. A URL in the following format without the Bing Maps Key is provided in the response to the URL request that you made to Create a Geocode Job and Upload Data. The URL is specified in a link field with an attribute of self. For more information, see Geocode Dataflow Response Description.

http://spatial.virtualearth.net/REST/v1/Dataflows/Geocode/jobID?output=output&key=BingMap

sKey

Template Parameters

?output= output &key= BingMap sKey Template Parameters Parameter names and values are not case-sensitive except for

Parameter names and values are not case-sensitive except for the key parameter value.

Parameter

Alias

Description

Values

jobID

 

Required. The ID of the job.

When you request a dataflow job, the job ID is returned in the ID field of the response. For more information, see Geocode Dataflow Response Description.

Example:

e14b1d9bd65c4b9d99d267bbb8102ccf

key

 

Required. The Bing Maps Key that you used to create the

A Bing Maps Key from the Bing Maps Account Center.

Example:

Parameter

Alias

Description

Values

   

geocode job.

key=abc123def456ghi789abc123def456ghi789

output

o

Optional. The output format for the response.

One of the following values:

json [default]

xml

 

Example: o=xml

Examples

This example requests resource information for the job with an ID of e14b1d9bd65c4b9d99d267bbb8102ccf that was created by using the Bing Maps Key

b1c323ea234b1c323ea234b1c323ea234.

http://spatial.virtualearth.net/REST/v1/Dataflows/Geocode/e14b1d9bd65c4b9d99d267bbb8102cc

f?key=b1c323ea234b1c323ea234b1c323ea234

Response

This URL supports the following response formats.



JSON: application/json



XML: application/xml

For information about the response, see Geocode Dataflow Response Description.

Sample Code

The following code shows how to get the status of a geocode job. This code is part of a complete Geocode Dataflow code sample. To view the complete code sample, see Geocode Dataflow Sample Code. You may also want to read the Geocode Dataflow Walkthrough to get a step-by- step description of how to use the Geocode Dataflow. The walkthrough includes example URLs and HTTP responses.

class DownloadDetails

{

 

public string jobStatus { get; set; }

public string suceededlink { get; set; }

public string failedlink { get; set; }

}

//Checks the status of a dataflow job and defines the URLs to use to download results when the job is completed.

//Parameters:

//

dataflowJobLocation: The URL to use to check status for a job.

//

key: The Bing Maps Key for this job. The same key is used to create the job and

download results.

//Return value: A DownloadDetails object that contains the status of the geocode dataflow job (Completed, Pending, Aborted).

//

links to download the results

When the status is set to Completed, DownloadDetails also contains the

static DownloadDetails CheckStatus(string dataflowJobLocation, string key)

{

DownloadDetails statusDetails = new DownloadDetails();

statusDetails.jobStatus = "Pending";

//Build the HTTP Request to get job status

UriBuilder uriBuilder = new UriBuilder(dataflowJobLocation + @"?key=" + key + "&output=xml");

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriBuilder.Uri);

request.Method = "GET";

//Submit the request and read the response to get job status and to retrieve the links for

// downloading the job results

//Note: The following conditional statements make use of the fact that the 'Status' field will

// always appear after the 'Link' fields in the HTTP response.

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())

{

if (response.StatusCode != HttpStatusCode.OK)

throw new Exception ("An HTTP error status code was encountered when checking job status.");

using (Stream receiveStream = response.GetResponseStream())

{

XmlTextReader reader = new XmlTextReader(receiveStream);

while (reader.Read())

{

 

if (reader.IsStartElement())

{

if (reader.Name.Equals("Status"))

{

 

//return job status

statusDetails.jobStatus = reader.ReadString();

return (statusDetails);

 

}

else if (reader.Name.Equals("Link"))

{

 

//Set the URL location values for retrieving

// successful and failed job results

reader.MoveToFirstAttribute();

if (reader.Value.Equals("output"))

{

reader.MoveToNextAttribute();

if (reader.Value.Equals("succeeded"))

{

statusDetails.suceededlink = reader.ReadString();

}

else if (reader.Value.Equals("failed"))

{

statusDetails.failedlink = reader.ReadString();

}

}

 

}

}

}

}

}

return (statusDetails);

}

HTTP Status Codes

} } return (statusDetails); } HTTP Status Codes For more details about these HTTP status codes,

For more details about these HTTP status codes, see Status Codes and Errors.

When the request is successful, the following HTTP status code is returned.



When the request is not successful, the response returns one of the following HTTP status codes.







200

400

500

503

Download Geocode Job Results

The URLs to download results from a Geocode Job are provided when your job has completed and you request job status. When your job has completed, the Status field in the job status response is set to Completed and the URLs to use to download processed data are defined in the response as XML Link values, or as part of a JSON links collection. You can distinguish these link elements in the response because they have the attribute role set to output. These link elements also specify the name attribute and set it to succeeded or failed to identify a download URL for data that was processed successfully or for data that encountered errors during processing. A link does not appear if there is no data to download. Therefore, if all your data was processed successfully, a link with the name attribute and set it to failed will not appear in the response. The following are examples of these link elements.

XML

<Link role="output"

name="succeeded">https://spatial.virtualearth.net/REST/v1/dataflows/Geocode/5bf10c37df944

083b1879fbb0556e67e/output/succeeded</Link>

<Link role="output"

name="failed">https://spatial.virtualearth.net/REST/v1/dataflows/Geocode/5bf10c37df944083

b1879fbb0556e67e/output/failed</Link>

JSON

"links":[

{

"name":"succeeded",

"role":"output",

"url":"https:\/\/spatial.virtualearth.net\/REST\/v1\/dataflows\/Geocode\/5bf10c3

7df944083b1879fbb0556e67e\/output\/succeeded"

},

{

"name":"failed",

"role":"output",

"url":"https:\/\/spatial.virtualearth.net\/REST\/v1\/dataflows\/Geocode\/5bf10c3

7df944083b1879fbb0556e67e\/output\/failed"

]

}

To use these URLs, you must add the Bing Maps Key parameter that you used to create the job. For example, to download the data that was processed successfully in the above example, you would add the parameter key MyDataflowJobKey where MyDataflowJobKey is the Bing Maps Key that you used to create the job.

https://spatial.virtualearth.net/REST/v1/dataflows/Geocode/5bf10c37df944083b1879fbb0556e6

7e/output/succeeded?key=MyDataflowJobKey

For information about the Geocode Dataflow data schema, see Geocode Dataflow Data Schema.

Sample Code

The following code shows how to download the results of a geocode job. The geocoded results are saved in text files. This code is part of a complete Geocode Dataflow code sample. To view the complete code sample, see Geocode Dataflow Sample Code. You may also want to read the Geocode Dataflow Walkthrough to get a step-by-step description of how to use the Geocode Dataflow. The walkthrough includes example URLs and HTTP responses.

//Downloads job results to files names Success.txt (successfully geocoded results) and

//

Failed.txt (info about spatial data that was not geocoded successfully).

//Parameters:

//

results.

statusDetails: Inclues job status and the URLs to use to download all geocoded

//

job status.

key: The Bing Maps Key for this job. The same key is used to create the job and get

static void DownloadResults(DownloadDetails statusDetails, string key)

{

//Write the results for data that was geocoded successfully to a file named Success.xml

if (statusDetails.suceededlink != null && !statusDetails.suceededlink.Equals(String.Empty))

{

//Create a request to download successfully geocoded data. You must add the Bing Maps Key to the

// download location URL provided in the response to the job status request.

UriBuilder successUriBuilder = new UriBuilder(statusDetails.suceededlink + @"?key=" + key);

HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(successUriBuilder.Uri);

request1.Method = "GET";

using (HttpWebResponse response = (HttpWebResponse)request1.GetResponse())

{

if (response.StatusCode != HttpStatusCode.OK)

throw new Exception ("An HTTP error status code was encountered when downloading results.");

using (Stream receiveStream = response.GetResponseStream())

{

StreamWriter successfile = new StreamWriter("Success.txt");

using (StreamReader r = new StreamReader(receiveStream))

{

string line;

while ((line = r.ReadLine()) != null)

{

successfile.Write(line);

}

}

successfile.Close();

}

}

}

//If some spatial data could not be geocoded, write the error information to a file called Failed.xml

if (statusDetails.failedlink != null && !statusDetails.failedlink.Equals(String.Empty))

{

//Create an HTTP request to download error information. You must add the Bing Maps Key to the

// download location URL provided in the response to the job status request.

UriBuilder failedUriBuilder = new UriBuilder(statusDetails.failedlink + @"?key="

+ key);

HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(failedUriBuilder.Uri);

request2.Method = "GET";

using (HttpWebResponse response = (HttpWebResponse)request2.GetResponse())

{

if (response.StatusCode != HttpStatusCode.OK)

throw new Exception ("An HTTP error status code was encountered when downloading results.");

using (Stream receiveStream = response.GetResponseStream())

{

StreamWriter failedfile = new StreamWriter("Failed.txt");

using (StreamReader r = new StreamReader(receiveStream))

{

string line;

while ((line = r.ReadLine()) != null)

{

failedfile.Write(line);

}

}

}

}

failedfile.Close();

}

}

Geocode Dataflow Response Description

The following tables describe the response syntax for a Geocode Dataflow request in a set of hierarchical tables. Examples in JSON and XML formats are also provided.

Response

The following fields are the top-level fields in the Geocode Dataflow response. Additional tables describe the fields in each of the collections.

JSON

XML

Type

Description

copyright

Copyright

string

A

copyright

notice.

brandLogoUri

BrandLogoUri

string

A

URL that

references a

brand image to

support

contractual

branding

requirements.

statusCode

StatusCode

integer

The HTTP Status code for the request.

statusDescription

StatusDescription

string

A

description of

the HTTP

status code.

authenticationResultCode

AuthenticationResultCode

One of the following values:

A

status code

that offers

ValidCredentials

additional

information

JSON

XML

Type

Description

   

InvalidCredentials

about

CredentialsExpired

authentication

success or

NotAuthorized

failure.

NoCredentials

None

traceId

TraceId

string

A

unique

identifier for the

request.

resourceSets

ResourceSets

collection

A

collection of

ResourceSet

objects. A

ResourceSet is

a

container of

Resources

returned by the request. For

more

information,

see the

ResourceSet

section below.

errorDetails

ErrorDetails

string[]

A

collection of

error

descriptions.

For example,

ErrorDetails

can identify

parameter

values that are not valid or are missing.

ResourceSet

The ResourceSet container provides the following information.

JSON

XML

Type

Description

estimatedTotal

EstimatedTotal

long

An estimate of the total number of resources in

JSON

XML

Type

Description

     

the ResourceSet.

resources

Resources

collection

A collection of one or more DataflowJob resources. Information about the DataflowJob resource is found in the DataflowJob section.

DataflowJob

The DataflowJob resource container provides the following information.

JSON

XML

Type

Description

id

Id

string

A

unique string that

identifies the dataflow job. There are no

requirements for the string format.

links

Link

URL

A

URL that is defined

by its role and name attributes.

“role”:”self”: Use to

check the status of your job.

“role”:”output” and “name”:“succeeded”:

Use to download data that was processed successfully.

“role”:”output” and “name”:“failed”: Use to

download data that was not processed successfully.

description

Description

string

A

user-defined

description of the dataflow job. If a description is not

JSON

XML

Type

Description

     

specified when the workflow is created, this field is not included or the value is null.

status

Status

One of the following values:

The status of the dataflow job.

Pending: The

dataflow job is processing.

Completed: The

dataflow job has completed. A status of completed does not indicate success.

Aborted: The

workflow stopped because of an error.

createdDate

CreatedDate

DateTime

The date and time that the dataflow job was created.

completedDate

CompletedDate

DateTime

The date and time that the dataflow job is completed. If the Status field is set to Pending,

the CompletedDate field

is not shown or is empty.

totalEntityCount

TotalEntityCount

integer

The total number of entities that were uploaded.

processedEntityCount

ProcessedEntityCount

integer

The number of entities that were processed. This number included entities that were processed successfully

JSON

XML

Type

Description

     

and those that failed. If the field is set to 0, the number of processed entries is not known.

failedEntityCount

FailedEntityCount

integer

The number of entities that did not process successfully because of an error.

errorMessage

ErrorMessage

string

Additional error information that is provided when the

Status is set to Aborted.

DataflowJob Response Examples

The following examples show DataflowJob resource content in JSON and XML formats.

JSON Example

{

"authenticationResultCode":"ValidCredentials",

"brandLogoUri":"http:\/\/spatial.virtualearth.net\/Branding\/logo_powered_by.png",

"copyright":"© 2010 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",

"resourceSets":[

{

"estimatedTotal":1,

"resources":[

{

" type":"DataflowJob:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1",

"id":"5bf10c37df944083b1879fbb0556e67e",

"links":[

{

"role":"self",

"url":"https:\/\/spatial.virtualearth.net\/REST\/v1\/dataflows\/Geocode\/5bf10c37df944083

b1879fbb0556e67e"

},

{

"name":"succeeded",

"role":"output",

"url":"https:\/\/spatial.virtualearth.net\/REST\/v1\/dataflows\/Geocode\/5bf10c37df944083

b1879fbb0556e67e\/output\/succeeded"

},

{

"name":"failed",

"role":"output",

"url":"https:\/\/spatial.virtualearth.net\/REST\/v1\/dataflows\/Geocode\/5bf10c37df944083

b1879fbb0556e67e\/output\/failed"

],

}

"completedDate":"Mon, 10 May 2010 20:23:49 GMT",

"createdDate":"Mon, 10 May 2010 20:22:35 GMT",

"description":"Xml",

"failedEntityCount":2,

"processedEntityCount":12,

"status":"Completed",

"totalEntityCount":12

],

}

]

}

"statusCode":200,

"statusDescription":"OK",

"traceId":"e8bfe25fdc4f4bc5824cda4e568e1c19"

}

XML Example

<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1">

<Copyright>© 2010 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.</Copyright>

<BrandLogoUri>http://spatial.virtualearth.net/Branding/logo_powered_by.png</BrandLogoUri>

<StatusCode>200</StatusCode>

<StatusDescription>OK</StatusDescription>

<AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>

<TraceId>f65bd9af90e241b3a7d52316314eb352|BL12080319|02.00.103.1000|</TraceId>

<ResourceSets>

<ResourceSet>

<EstimatedTotal>1</EstimatedTotal>

<Resources>

<DataflowJob>

<Id>5bf10c37df944083b1879fbb0556e67e</Id>

<Link role="self">https://spatial.virtualearth.net

/REST/v1/dataflows/Geocode/5bf10c37df944083b1879fbb0556e67e</Link>

<Link role="output"

name="succeeded">https://spatial.virtualearth.net/REST/v1/dataflows/Geocode/5bf10c37df944

083b1879fbb0556e67e/output/succeeded</Link>

<Link role="output"

name="failed">https://spatial.virtualearth.net/REST/v1/dataflows/Geocode/5bf10c37df944083

b1879fbb0556e67e/output/failed</Link>

<Description>Xml</Description>

<Status>Completed</Status>

<CreatedDate>2010-05-10T13:22:35.0553408-07:00</CreatedDate>

<CompletedDate>2010-05-10T13:23:49.1959658-07:00</CompletedDate>

<TotalEntityCount>12</TotalEntityCount>

<ProcessedEntityCount>12</ProcessedEntityCount>

<FailedEntityCount>2</FailedEntityCount>

</DataflowJob>

</Resources>

</ResourceSet>

</ResourceSets>

</Response>

Geocode Dataflow Walkthrough

Use the Geocode Dataflow API to geocode large sets of spatial data by using the following steps.

Uploading Your Spatial Data

Format the data

To create a job to geocode a set of spatial data, your data must conform to the input schema as defined in Geocode Dataflow Data Schema and be provided in XML format, or as text strings delimited by the comma, tab, or pipe (|) character.

The following is an XML example that contains data to geocode. You can find examples in other formats in Geocode Dataflow Sample Input and Output Data.

<GeocodeFeed xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeEntity Id="0">

<GeocodeRequest Culture="en-US">

<Address AddressLine="1601 15th St NW # B" AdminDistrict="WA" Locality="Auburn" CountryRegion="US" PostalCode="98001" />

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="1">

<GeocodeRequest Culture="en-US">

<Address AddressLine="36215 55th Ave S" AdminDistrict="WA" Locality="Auburn" CountryRegion="US" PostalCode="98001" />

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="2">

<GeocodeRequest Culture="en-US">

<Address AddressLine="10 2nd St SW" AdminDistrict="WA" Locality="Auburn" CountryRegion="US" PostalCode="98001" />

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="3">

<GeocodeRequest Culture="en-US">

<Address AddressLine="35217 56th Ave S # B" AdminDistrict="WA" Locality="Auburn" CountryRegion="US" PostalCode="98001" />

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="4">

<GeocodeRequest Culture="en-US">

<Address AddressLine="4303 S 296th Pl" AdminDistrict="WA" Locality="Auburn" CountryRegion="US" PostalCode="98001" />

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="5">

<GeocodeRequest Culture="en-US">

<Address AddressLine="" AdminDistrict="" />

</GeocodeRequest>

</GeocodeEntity>

</GeocodeFeed>

Upload the data and create the geocode job

To geocode the data, you upload the data and create a geocode job with a URL. The URL for this example has the following format. For more information, see Create a Geocode Job and Upload Data.

information, see Create a Geocode Job and Upload Data . Both HTTP and HTTPS protocols are

Both HTTP and HTTPS protocols are supported. The HTTPS protocol is recommended for geocode jobs that require you to secure your information.

http://spatial.virtualearth.net/REST/v1/Dataflows/Geocode?description=Geocode

Demo&input=xml&output=xml&key=YourBingMapsKey

When you make this request, the resource provided by the response is provided as a DataflowJob. This structure of this resource includes a set of URLs defined as Link elements. You can download the results of your job by using the URLs defined by the Link elements that have name attributes set to succeeded and failed. However, before downloading you must first confirm that your job has completed by checking the job status, as discussed in the next section. Notice that the status for the resource in this example indicates that the geocode job is Pending. For more information about the DataflowJob resource, see Geocode Dataflow Response Description.

<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1">

<Copyright>Copyright © 2010 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the

content and any results may not be used, reproduced or transmitted in any manner without express written permission

from Microsoft Corporation.</Copyright>

<BrandLogoUri>http://spatial.virtualearth.net/Branding/logo_powered_by.png</BrandLogoUri>

<StatusCode>201</StatusCode>

<StatusDescription>Created</StatusDescription>

<AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>

<TraceId>b1aae77f9b9145ffa87d97d7d405cffd</TraceId>

<ResourceSets>

<ResourceSet>

<EstimatedTotal>1</EstimatedTotal>

<Resources>

<DataflowJob>

<Id>e14b1d9bd65c4b9d99d267bbb8102ccf</Id>

<Link

role="self">https://spatial.virtualearth.net/REST/v1/dataflows/geocode/e14b1d9bd65c4b9d99

d267bbb8102ccf</Link>

<Description>Geocode Demo</Description>

<Status>Pending</Status>

<CreatedDate>2010-03-09T15:15:51.8326153-08:00</CreatedDate>

<CompletedDate xsi:nil="true" />

<TotalEntityCount>0</TotalEntityCount>

<ProcessedEntityCount>0</ProcessedEntityCount>

<FailedEntityCount>0</FailedEntityCount>

</DataflowJob>

</Resources>

</ResourceSet>

</ResourceSets>

</Response>

Checking Job Status

To find out the status of a geocode job, use the URL provided in the response to the request to create the job. The URL is specified in the Link element with the role attribute set to self. You

must specify the Bing Maps Key that you used to create the job. For more information, see Get Status of a Geocode Job. The URL to request status of a job has the following format.

https://spatial.virtualearth.net/REST/v1/dataflows/geocode/JobID?key=YourBingMapsKey

When you make this request, you receive a response that shows the job status as a DataflowJob resource. The DataflowJob resource in this example has a status of Completed. You can use the URLs in the Link elements to download the data as described in the next section.

<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1">

<Copyright>Copyright © 2010 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the

content and any results may not be used, reproduced or transmitted in any manner without express written permission

from Microsoft Corporation.</Copyright>

<BrandLogoUri>http://spatial.virtualearth.net/Branding/logo_powered_by.png</BrandLogoUri>

<StatusCode>200</StatusCode>

<StatusDescription>OK</StatusDescription>

<AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>

<TraceId>2a4fcb1fd1274497ab8ed84955012264</TraceId>

<ResourceSets>

<ResourceSet>

<EstimatedTotal>1</EstimatedTotal>

<Resources>

<DataflowJob>

<Id>e14b1d9bd65c4b9d99d267bbb8102ccf</Id>

<Link

role="self">https://spatial.virtualearth.net/REST/v1/dataflows/geocode/e14b1d9bd65c4b9d99

d267bbb8102ccf</Link>

<Link role="output"

name="succeeded">https://spatial.virtualearth.net/REST/v1/dataflows/geocode/e14b1d9bd65c4

b9d99d267bbb8102ccf/output/succeeded</Link>

<Description>Geocode Job 1</Description>

<Status>Completed</Status>

<CreatedDate>2010-03-08T16:35:00.2429749-08:00</CreatedDate>

<CompletedDate>2010-03-08T16:44:00.9349209-08:00</CompletedDate>

<TotalEntityCount>6</TotalEntityCount>

<ProcessedEntityCount>6</ProcessedEntityCount>

<FailedEntityCount>0</FailedEntityCount>

</DataflowJob>

</Resources>

</ResourceSet>

</ResourceSets>

</Response>

If your job status is Aborted, then the job ended due to an error and an ErrorMessage element appears in the response and contains error information.

Downloading Results

When the status of your job is set to Completed, you can download the results of the geocode job. The results are available for download for fourteen (14) calendar days. The URLs to download data that was geocoded successfully and to download data that was not geocoded successfully are provided in the DataflowJob resource provided for the job. The URLs are identified by their name attribute that are set to succeeded and failed. A succeeded or failed Link URL only appears in the response if there is corresponding data to download. If all the data was geocoded successfully, a failed Link URL does not appear. To download data with these URLs, you must add the key parameter and set it to the Bing Maps Key that you used to create the job

The following URL examples show the format for downloading data and include the Bing Maps Key parameter. The results of geocoding the input in this walkthrough are also provided. Note that the downloaded results are provided in the same format as the input values. To view examples in other data formats, see Geocode Dataflow Sample Input and Output Data.

URL (name=succeeded)

https://spatial.virtualearth.net/REST/v1/dataflows/geocode/JobID/output/succeeded?key=Bin

gMapsKey

Results

<GeocodeFeed xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode" >

<GeocodeEntity Id="0" xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="1601 15th St NW # B" AdminDistrict="WA" CountryRegion="US" Locality="Auburn" PostalCode="98001" />

</GeocodeRequest>

<GeocodeResponse DisplayName="1601 15th St NW, Auburn, WA 98001-3501" EntityType="Address" Confidence="High" StatusCode="Success">

<Address AddressLine="1601 15th St NW" AdminDistrict="WA" CountryRegion="United States" FormattedAddress="1601 15th St NW, Auburn, WA 98001-3501" Locality="Auburn" PostalCode="98001-3501" />

<RooftopLocation Longitude="-122.254631" Latitude="47.323132" />

<InterpolatedLocation Longitude="-122.254631" Latitude="47.322481" />

</GeocodeResponse>

</GeocodeEntity>

<GeocodeEntity Id="1" xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="36215 55th Ave S" AdminDistrict="WA" CountryRegion="US" Locality="Auburn" PostalCode="98001" />

</GeocodeRequest>

<GeocodeResponse DisplayName="36215 55th Ave S, Auburn, WA 98001-9383" EntityType="Address" Confidence="High" StatusCode="Success">

<Address AddressLine="36215 55th Ave S" AdminDistrict="WA" CountryRegion="United States" FormattedAddress="36215 55th Ave S, Auburn, WA 98001-9383" Locality="Auburn" PostalCode="98001-9383" />

<RooftopLocation Longitude="-122.267006" Latitude="47.276497" />

<InterpolatedLocation Longitude="-122.266451" Latitude="47.276141" />

</GeocodeResponse>

</GeocodeEntity>

<GeocodeEntity Id="2" xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="10 2nd St SW" AdminDistrict="WA" CountryRegion="US" Locality="Auburn" PostalCode="98001" />

</GeocodeRequest>

<GeocodeResponse DisplayName="10 2nd St SW, Auburn, WA 98001-5270" EntityType="Address" Confidence="High" StatusCode="Success">

<Address AddressLine="10 2nd St SW" AdminDistrict="WA" CountryRegion="United States" FormattedAddress="10 2nd St SW, Auburn, WA 98001-5270" Locality="Auburn" PostalCode="98001-5270" />

<InterpolatedLocation Longitude="-122.230068" Latitude="47.30564" />

</GeocodeResponse>

</GeocodeEntity>

<GeocodeEntity Id="3" xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="35217 56th Ave S # B" AdminDistrict="WA" CountryRegion="US" Locality="Auburn" PostalCode="98001" />

</GeocodeRequest>

<GeocodeResponse DisplayName="35217 56th Ave S, Auburn, WA 98001-9204" EntityType="Address" Confidence="High" StatusCode="Success">

<Address AddressLine="35217 56th Ave S" AdminDistrict="WA" CountryRegion="United States" FormattedAddress="35217 56th Ave S, Auburn, WA 98001-9204" Locality="Auburn" PostalCode="98001-9204" />

<RooftopLocation Longitude="-122.265434" Latitude="47.285744" />

<InterpolatedLocation Longitude="-122.264971" Latitude="47.285741" />

</GeocodeResponse>

</GeocodeEntity>

<GeocodeEntity Id="4" xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="4303 S 296th Pl" AdminDistrict="WA" CountryRegion="US" Locality="Auburn" PostalCode="98001" />

</GeocodeRequest>

<GeocodeResponse DisplayName="4303 S 296th Pl, Auburn, WA 98001-1566" EntityType="Address" Confidence="High" StatusCode="Success">

<Address AddressLine="4303 S 296th Pl" AdminDistrict="WA" CountryRegion="United States" FormattedAddress="4303 S 296th Pl, Auburn, WA 98001-1566" Locality="Auburn" PostalCode="98001-1566" />

<RooftopLocation Longitude="-122.279762" Latitude="47.336163" />

<InterpolatedLocation Longitude="-122.279762" Latitude="47.33637" />

</GeocodeResponse>

</GeocodeEntity>

</GeocodeFeed>

URL (name=failed)

https://spatial.virtualearth.net/REST/v1/dataflows/geocode/JobID/output/failed?key=BingMa

psKey

Results

<GeocodeFeed xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode" >

<GeocodeEntity Id="5" xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="" AdminDistrict="" />

</GeocodeRequest>

<GeocodeResponse StatusCode="BadRequest" FaultReason="Parameter name: Address" />

</GeocodeEntity>

</GeocodeFeed>

Geocode Dataflow Sample Code

The following sample code uses the Geocode Dataflow to geocode spatial data.

Notes:



The code uses the functionality included in Microsoft® .NET 2.0 and is written as a console application.



The code accepts input data in any of the formats supported by the Geocode Dataflow. Examples of supported data formats are XML and CSV(comma-separated values). See Create a Geocode Job and Upload Data for more information about supported data formats.



The code processes HTTP requests returned in XML format.



The results of the geocode job are output to files named succeeded.txt and failed.txt.

using System;

using System.IO;

using System.Net;

using System.Text;

using System.Threading;

using System.Xml;

//This C# code sample shows how to geocode data using the Geocode Dataflow REST API.

//For more information on this API, see the Bing Spatial Data Services SDK on MSDN:

// http://msdn.microsoft.com/en-us/library/ff701734.aspx

namespace GeocodeDataFlowExample

{

//A summary of status information returned in the response when you check

// job status.

class DownloadDetails

{

public string jobStatus { get; set; }

public string suceededlink { get; set; }

public string failedlink { get; set; }

}

class Program

{

//Creates a geocode dataflow job and uploads spatial data to process.

//Parameters:

//

dataFilePath: The path to the file that contains the spatial data to

geocode.

//

dataFormat: The format of the input data. Possible values are xml, csv, tab

and pipe.

//

key: The Bing Maps Key to use for this job. The same key is used to get job

status and download results.

//

description: Text that is used to describe the geocode dataflow job.

//Return value : A URL that defines the location of the geocode dataflow job that was created.

static string CreateJob(string dataFilePath, string dataFormat, string key, string description)

{

//Define parameters for the HTTP request

//

// The 'Content-Type' header of the HTTP Request must be "text/plain" or "application/xml"

// depending on the input data format.

//

string contentType = "text/plain";

if (dataFormat.Equals("xml", StringComparison.OrdinalIgnoreCase))

contentType = "application/xml";

StringBuilder queryStringBuilder = new StringBuilder();

//

// The 'input'(input format) and 'key' (Bing Maps Key) parameters are

required.

//

queryStringBuilder.Append("input=").Append(Uri.EscapeUriString(dataFormat));

queryStringBuilder.Append("&");

queryStringBuilder.Append("key=").Append(Uri.EscapeUriString(key));

if (!String.IsNullOrEmpty(description))

{

//

// The 'description' parameter is optional.

//

queryStringBuilder.Append("&");

queryStringBuilder.Append("description=").Append(Uri.EscapeUriString(description));

}

//Build the HTTP URI that will upload and create the geocode dataflow job

UriBuilder uriBuilder = new UriBuilder("http://spatial.virtualearth.net");

uriBuilder.Path = "/REST/v1/dataflows/geocode";

uriBuilder.Query = queryStringBuilder.ToString();

//Include the data to geocode in the HTTP request

using (FileStream dataStream = File.OpenRead(dataFilePath))

{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriBuilder.Uri);

//

// The HTTP method must be 'POST'.

//

request.Method = "POST";

request.ContentType = contentType;

using (Stream requestStream = request.GetRequestStream())

{

 

byte[] buffer = new byte[16384];

int bytesRead = dataStream.Read(buffer, 0, buffer.Length);

while (bytesRead > 0)

{

requestStream.Write(buffer, 0, bytesRead);

bytesRead = dataStream.Read(buffer, 0, buffer.Length);

}

}

//Submit the HTTP request and check if the job was created successfully.

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())

{

//

// If the job was created successfully, the status code should be

// 201 (Created) and the 'Location' header should contain a URL

// that defines the location of the new dataflow job. You use this

// URL with the Bing Maps Key to query the status of your job.

//

if (response.StatusCode != HttpStatusCode.Created)

throw new Exception ("An HTTP error status code was encountered when creating the geocode job.");

string dataflowJobLocation = response.GetResponseHeader("Location");

if (String.IsNullOrEmpty(dataflowJobLocation))

throw new Exception ("The 'Location' header is missing from the HTTP response when creating a goecode job.");

return dataflowJobLocation;

}

}

}

//Checks the status of a dataflow job and defines the URLs to use to download results when the job is completed.

//Parameters:

//

dataflowJobLocation: The URL to use to check status for a job.

//

key: The Bing Maps Key for this job. The same key is used to create the job

and download results.

//Return value: A DownloadDetails object that contains the status of the geocode dataflow job (Completed, Pending, Aborted).

//

When the status is set to Completed, DownloadDetails also

contains the links to download the results

static DownloadDetails CheckStatus(string dataflowJobLocation, string key)

{

DownloadDetails statusDetails = new DownloadDetails();

statusDetails.jobStatus = "Pending";

//Build the HTTP Request to get job status

UriBuilder uriBuilder = new UriBuilder(dataflowJobLocation + @"?key=" + key + "&output=xml");

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriBuilder.Uri);

request.Method = "GET";

//Submit the request and read the response to get job status and to retrieve the links for

// downloading the job results

//Note: The following conditional statements make use of the fact that the 'Status' field will

// always appear after the 'Link' fields in the HTTP response.

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())

{

if (response.StatusCode != HttpStatusCode.OK)

throw new Exception ("An HTTP error status code was encountered when checking job status.");

using (Stream receiveStream = response.GetResponseStream())

{

XmlTextReader reader = new XmlTextReader(receiveStream);

while (reader.Read())

{

if (reader.IsStartElement())

{

if (reader.Name.Equals("Status"))

{

 

//return job status

statusDetails.jobStatus = reader.ReadString();

return (statusDetails);

}

else if (reader.Name.Equals("Link"))

{

//Set the URL location values for retrieving

// successful and failed job results

reader.MoveToFirstAttribute();

if (reader.Value.Equals("output"))

{

reader.MoveToNextAttribute();

if (reader.Value.Equals("succeeded"))

{

statusDetails.suceededlink = reader.ReadString();

}

else if (reader.Value.Equals("failed"))

{

statusDetails.failedlink = reader.ReadString();

}

}

}

}

}

}

}

return (statusDetails);

}

//Downloads job results to files names Success.txt (successfully geocoded results) and

//

Failed.txt (info about spatial data that was not geocoded successfully).

//Parameters:

//

statusDetails: Inclues job status and the URLs to use to download all

geocoded results.

//

key: The Bing Maps Key for this job. The same key is used to create the job

and get job status.

static void DownloadResults(DownloadDetails statusDetails, string key)

{

//Write the results for data that was geocoded successfully to a file named

Success.xml

if (statusDetails.suceededlink != null && !statusDetails.suceededlink.Equals(String.Empty))

{

//Create a request to download successfully geocoded data. You must add the Bing Maps Key to the

// download location URL provided in the response to the job status

request.

UriBuilder successUriBuilder = new UriBuilder(statusDetails.suceededlink + @"?key=" + key);

HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(successUriBuilder.Uri);

request1.Method = "GET";

using (HttpWebResponse response =

(HttpWebResponse)request1.GetResponse())

{

if (response.StatusCode != HttpStatusCode.OK)

throw new Exception ("An HTTP error status code was encountered when downloading results.");

using (Stream receiveStream = response.GetResponseStream())

{

 

StreamWriter successfile = new StreamWriter("Success.txt");

using (StreamReader r = new StreamReader(receiveStream))

{

string line;

while ((line = r.ReadLine()) != null)

{

successfile.Write(line);

}

}

successfile.Close();

}

}

}

//If some spatial data could not be geocoded, write the error information to a file called Failed.xml

if (statusDetails.failedlink != null && !statusDetails.failedlink.Equals(String.Empty))

{

//Create an HTTP request to download error information. You must add the Bing Maps Key to the

// download location URL provided in the response to the job status

request.

UriBuilder failedUriBuilder = new UriBuilder(statusDetails.failedlink +

@"?key=" + key);

HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(failedUriBuilder.Uri);

request2.Method = "GET";

using (HttpWebResponse response =

(HttpWebResponse)request2.GetResponse())

{

if (response.StatusCode != HttpStatusCode.OK)

throw new Exception ("An HTTP error status code was encountered when downloading results.");

using (Stream receiveStream = response.GetResponseStream())

{

StreamWriter failedfile = new StreamWriter("Failed.txt");

using (StreamReader r = new StreamReader(receiveStream))

{

string line;

while ((line = r.ReadLine()) != null)

{

failedfile.Write(line);

}

}

}

failedfile.Close();

}

}

}

//

// Sample command-line:

// GeocodeDataFlowExample.exe <dataFilePath> <dataFormat> <key> [<description>]

//

// Where:

// <dataFilePath> is a path to the data file containing entities to geocode.

// <dataFormat> is one of these types: xml, csv, tab, pipe.

// <key> is a Bing Maps Key from http://www.bingmapsportal.com.

// <description> is an optional description for the dataflow job.

//

static void Main(string[] args)

{

string dataFilePath = args[0];

string dataFormat = args[1];

string key = args[2];

string description = null;

try

{

if (args.Length > 3)

description = args[3];

string dataflowJobLocation = CreateJob(dataFilePath, dataFormat, key,

description);

Console.WriteLine("Dataflow Job Location: {0}", dataflowJobLocation);

//Continue to check the dataflow job status until the job has completed

DownloadDetails statusDetails = new DownloadDetails();

do

{

statusDetails = CheckStatus(dataflowJobLocation, key);

Console.WriteLine("Dataflow Job Status: {0}", statusDetails.jobStatus);

if (statusDetails.jobStatus== "Aborted")

throw new Exception("Job was aborted due to an error.");

Thread.Sleep(30000); //Get status every 30 seconds

}

while (statusDetails.jobStatus.Equals("Pending"));

//When the job is completed, get the results

//Two files are created to record the results:

// Success.xml contains the data that was successfully geocoded

// Failed.mxl contains the data that could not be geocoded

DownloadResults(statusDetails, key);

}

catch (Exception e)

{

Console.WriteLine("Exception :" + e.Message);

}

}

}

}

Geocode Dataflow Data Schema

The Geocode Dataflow API supports the following formats for uploading and downloading spatial data:



 XML

Text files with values separated by comma, tab, or pipe (|) characters.

This topic describes the spatial data schema for the Geocode Dataflow API. Text file and the XML schema definitions are provided along with descriptions of the fields. For examples of input and output spatial data in all formats, see Geocode Dataflow Sample Input and Output Data.

Text File Schema

The following text file schema shows how the input and output values for the Geocode Dataflow are organized in a text file. Note that there are GeocodeRequest, GeocodeResponse, and ReverseGeocodeRequest values. The Geocode Request fields define location information to geocode. The ReverseGeocodeRequest fields provide latitude and longitude information to reverse geocode. The GeocodeReponse fields are populated with the processed output data. Each item of data must provide information or a blank entry for each of these fields. Descriptions of the fields are provided in the Data Schema Definitions section below.

GeocodeEntity/@Id

GeocodeEntity/GeocodeRequest/@Culture

GeocodeEntity/GeocodeRequest/@Query

GeocodeEntity/GeocodeRequest/Address/@AddressLine

GeocodeEntity/GeocodeRequest/Address/@AdminDistrict

GeocodeEntity/GeocodeRequest/Address/@CountryRegion

GeocodeEntity/GeocodeRequest/Address/@District

GeocodeEntity/GeocodeRequest/Address/@FormattedAddress

GeocodeEntity/GeocodeRequest/Address/@Locality

GeocodeEntity/GeocodeRequest/Address/@PostalCode

GeocodeEntity/GeocodeRequest/Address/@PostalTown

GeocodeEntity/GeocodeRequest/ConfidenceFilter/@MinimumConfidence

GeocodeEntity/GeocodeResponse/Address/@AddressLine

GeocodeEntity/GeocodeResponse/Address/@AdminDistrict

GeocodeEntity/GeocodeResponse/Address/@CountryRegion

GeocodeEntity/GeocodeResponse/Address/@District

GeocodeEntity/GeocodeResponse/Address/@FormattedAddress

GeocodeEntity/GeocodeResponse/Address/@Locality

GeocodeEntity/GeocodeResponse/Address/@PostalCode

GeocodeEntity/GeocodeResponse/Address/@PostalTown

GeocodeEntity/GeocodeResponse/RooftopLocation/@Latitude

GeocodeEntity/GeocodeResponse/RooftopLocation/@Longitude

GeocodeEntity/GeocodeResponse/InterpolatedLocation/@Latitude

GeocodeEntity/GeocodeResponse/InterpolatedLocation/@Longitude

GeocodeEntity/GeocodeResponse/@Confidence

GeocodeEntity/GeocodeResponse/@DisplayName

GeocodeEntity/GeocodeResponse/@EntityType

GeocodeEntity/GeocodeResponse/@StatusCode

GeocodeEntity/GeocodeResponse/@FaultReason

GeocodeEntity/ReverseGeocodeRequest/Location/@Latitude

GeocodeEntity/ReverseGeocodeRequest/Location/@Longitude

The following two input values show an address to geocode and a latitude and longitude pair to reverse geocode. Note that both examples contain a value or blank space for each element in the text file schema.

1,en-US,,16630 Redmond Way,WA,Redmond,98052,,,,,,,,,,,,,,,,,,,,,,,,

2,en-gb,,,,,,,,,,,,,,,,,,,,,,,,,,,,53.77848387,-1.719561517

XML Schema

The following schema is the XML schema for spatial data. Descriptions of the fields are provided in the Data Schema Definitions section below.

<?xml version="1.0" standalone="yes"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

targetNamespace="http://schemas.microsoft.com/search/local/2010/5/geocode"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<xs:complexType name="Address">

<xs:attribute name="AddressLine" type="xs:string"/>

<xs:attribute name="AdminDistrict" type="xs:string" />

<xs:attribute name="CountryRegion" type="xs:string" />

<xs:attribute name="District" type="xs:string" />

<xs:attribute name="FormattedAddress" type="xs:string" />

<xs:attribute name="Locality" type="xs:string" />

<xs:attribute name="PostalCode" type="xs:string" />

<xs:attribute name="PostalTown" type="xs:string" />

</xs:complexType>

<xs:element name="Address" type="Address" />

<xs:complexType name="Location">

<xs:attribute name="Latitude" type="xs:double" />

<xs:attribute name="Longitude" type="xs:double" />

</xs:complexType>

<xs:element name="Location" type="Location" />

<xs:element name="RooftopLocation" type="Location" />

<xs:element name="InterpolatedLocation" type="Location" />

<xs:complexType name="BaseGeoRequest" abstract="true" >

<xs:sequence />

<xs:attribute name="Culture" type="xs:string" />

</xs:complexType>

<xs:element name="BaseGeoRequest" type="BaseGeoRequest" abstract="true" />

<xs:complexType name="GeocodeRequest">

<xs:complexContent>

<xs:extension base="BaseGeoRequest">

<xs:sequence>

<xs:element ref="Address" minOccurs="0" maxOccurs="1" />

<xs:element name="ConfidenceFilter" minOccurs="0" maxOccurs="1">

<xs:complexType>

<xs:attribute name="MinimumConfidence" type="xs:string" />

</xs:complexType>

</xs:element>

</xs:sequence>

<xs:attribute name="Query" type="xs:string" />

</xs:extension>

</xs:complexContent>

</xs:complexType>

<xs:element name="GeocodeRequest" type="GeocodeRequest" substitutionGroup="BaseGeoRequest" />

<xs:complexType name="ReverseGeocodeRequest">

<xs:complexContent>

<xs:extension base="BaseGeoRequest">

<xs:sequence>

<xs:element ref="Location" />

</xs:sequence>

</xs:extension>

</xs:complexContent>

</xs:complexType>

<xs:element name="ReverseGeocodeRequest" type="ReverseGeocodeRequest" substitutionGroup="BaseGeoRequest" />

<xs:complexType name="GeocodeResponse">

<xs:sequence>

<xs:element ref="Address" minOccurs="0" maxOccurs="1" />

<xs:element ref="RooftopLocation" minOccurs="0" maxOccurs="1" />

<xs:element ref="InterpolatedLocation" minOccurs="0" maxOccurs="1" />

</xs:sequence>

<xs:attribute name="DisplayName" type="xs:string" />

<xs:attribute name="EntityType" type="xs:string" />

<xs:attribute name="Confidence" type="xs:string" />

<xs:attribute name="StatusCode" type="xs:string" />

<xs:attribute name="FaultReason" type="xs:string" />

</xs:complexType>

<xs:element name="GeocodeResponse" type="GeocodeResponse" />

<xs:complexType name="GeocodeEntity">

<xs:sequence>

<xs:element ref="BaseGeoRequest" minOccurs="0" maxOccurs="1" />

<xs:element ref="GeocodeResponse" minOccurs="0" maxOccurs="1" />

</xs:sequence>

<xs:attribute name="Id" type="xs:string" />

</xs:complexType>

<xs:element name="GeocodeEntity" type="GeocodeEntity" />

<xs:complexType name="GeocodeFeed">

<xs:sequence>

<xs:element ref="GeocodeEntity" maxOccurs="unbounded" />

</xs:sequence>

</xs:complexType>

<xs:element name="GeocodeFeed" type="GeocodeFeed" />

</xs:schema>

The following two input values show a location to geocode and a latitude and longitude pair to reverse geocode.

<GeocodeFeed>

<GeocodeEntity Id="001"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="16630 Redmond Way" AdminDistrict="WA" Locality="Redmond" PostalCode="98052" />

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="012"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<ReverseGeocodeRequest Culture="en-gb">

<Location Longitude="-1.71956151723862" Latitude="53.7784838676453"/>

</ReverseGeocodeRequest>

</GeocodeEntity>

</GeocodeFeed>

Data Schema Definitions

The following table provides descriptions of the fields in the spatial data schema. Field values are not case-sensitive.

Field

Operation

Values

Id

Geocode Request

A string that contains the ID of a spatial data input value.

Example: 1

Culture

Geocode Request

A

string specifying the culture.

Example: en-us [default]

Query

Geocode Request

A

query string that contains

address information to geocode.

Example: 1600 Pennsylvania Ave NW Washington DC

Field

Operation

Values

Address.AddressLine

Geocode Request

A

string specifying the street line

Geocode Response

of

an address. The AddressLine

property is the most precise, official line for an address relative to the postal agency that services the area specified by the Locality, PostalTown, or PostalCode properties.

Example: 1 Microsoft Way

Address.AdminDistrict

Geocode Request

A

string specifying the

Geocode Response

subdivision name within the country or region for an address. This element is also commonly treated as the first order administrative subdivision; but in some cases, it is the second, third, or fourth order subdivision within a country, a dependency, or a region.

Example: WA

Address.CountryRegion

Geocode Request

A

string specifying the country or

Geocode Response

region name of an address.

Example: US

Address.District

Geocode Request

A

string specifying the higher

level administrative subdivision

used in some countries or regions.

Address.FormattedAddress

Geocode Response

A

string that contains a full

formatted address

Note: Do not use this field as a geocode request value. This field is used in the response.

Address.Locality

Geocode Request

A

string specifying the populated

Geocode Response

place for the address. This commonly refers to a city, but may refer to a suburb or a neighborhood in certain countries.

Field

Operation

Values

   

Example: Seattle

Address.PostalCode

Geocode Request

A

string specifying the post

Geocode Response

code, postal code, or ZIP Code

of

an address.

Example: 98178

Address.PostalTown

Geocode Request

A

string specifying the postal city

of

an address.

ConfidenceFilter.MinimumConfidence

Geocode Request

A

string specifying the minimum

confidence required for the

result.

The following are possible confidence values:

 Low

 Medium

 High

Example: High

Location.Latitude

Reverse Geocode

A

set of double values

Location.Longitude

Request

representing degrees of latitude and longitude.

Valid range of latitude values: [- 90, +90]

Example: 47.673099

Valid range of longitude values:

[-180, +180]

Example: -122.11871

RooftopLocation.Latitude

Geocode Response

A

pair of double values

RooftopLocation.Longitude

representing degrees of latitude and longitude that are

associated with an address.

InterpolatedLocation.Latitude

Geocode Response

A

pair of double values

InterpolatedLocation.Longitude

representing degrees of latitude and longitude that are the result of interpolating between two points.

Confidence

Geocode Response

A

string specifying the

confidence of the result.

Field

Operation

Values

   

The following are possible confidence values:

 Low

 Medium

 High

DisplayName

Geocode Response

A

string specifying the display

name for the response.

Example: 16552 NE 74th St, Redmond, WA 98052-7804

EntityType

Geocode Response

A

string specifying the entity

type of the location.

Examples:

Address

RoadBlock

StatusCode

Geocode Response

A

string that provides

information about the success of

the operation.

Examples:

Success

BadRequest

FaultReason

Geocode Response

Information about an error that occurred during the geocode dataflow job. This value is provided only for data that was not processed successfully.

Example: The Address.FormattedAddress property must not be specified because it is an output-only property.

Geocode Dataflow Sample Input and Output Data

The following examples show sample input and output data for the Geocode Dataflow. The input data can be provided in an XML format or as sets of values separated by pipe (|), comma, or tab characters. The output data is provided in the same format as the input data. The data in these

examples contains location data to geocode and latitude and longitude pairs to reverse geocode. For information about the data schema, see Geocode Dataflow Data Schema.

The input data must use UTF-8 encoding.

XML Example

Input

<GeocodeFeed>

<GeocodeEntity Id="001"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="16630 Redmond Way" AdminDistrict="WA" Locality="Redmond" PostalCode="98052" />

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="002"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="16552 NE 74th St" AdminDistrict="WA" Locality="Redmond" />

<ConfidenceFilter MinimumConfidence="High" xmlns="" />

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="003"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US" Query="Seattle Space Needle">

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="004"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US" Query="">

<Address AddressLine="" AdminDistrict="" />

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="005"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="W Jefferson Blvd" AdminDistrict="CA" Locality="Los Angeles" PostalCode="90007" />

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="006"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AdminDistrict="CA" Locality="Los angeles" PostalCode="" />

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="007"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-ca" Query="Montreal,Canada">

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="008"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-CA">

<Address AddressLine="444 Kirkpatrick Cres NW" AdminDistrict="AB" Locality="Edmonton" PostalCode="" CountryRegion="Canada" />

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="009"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-gb" Query="BD4 9JB">

</GeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="010"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<ReverseGeocodeRequest Culture="en-US">

<Location Longitude="-122.11871" Latitude="47.673099"/>

</ReverseGeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="011"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<ReverseGeocodeRequest Culture="en-ca">

<Location Longitude="-113.403092450204" Latitude="53.4802172766598"/>

</ReverseGeocodeRequest>

</GeocodeEntity>

<GeocodeEntity Id="012"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<ReverseGeocodeRequest Culture="en-gb">

<Location Longitude="-1.71956151723862" Latitude="53.7784838676453"/>

</ReverseGeocodeRequest>

</GeocodeEntity>

</GeocodeFeed>

Successful Output The following is an example list of locations that were geocoded successfully.

<GeocodeFeed >

<GeocodeEntity Id="001"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="16630 Redmond Way" AdminDistrict="WA" Locality="Redmond" PostalCode="98052" />

</GeocodeRequest>

<GeocodeResponse DisplayName="16630 Redmond Way, Redmond, WA 98052-4434" EntityType="Address" Confidence="High" StatusCode="Success">

<Address AddressLine="16630 Redmond Way" AdminDistrict="WA" CountryRegion="United States" FormattedAddress="16630 Redmond Way, Redmond, WA 98052-4434" Locality="Redmond" PostalCode="98052-4434" />

<RooftopLocation Latitude="47.673302" Longitude="-122.118576" />

<InterpolatedLocation Latitude="47.673099" Longitude="-122.11871" />

</GeocodeResponse>

</GeocodeEntity>

<GeocodeEntity Id="002"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="16552 NE 74th St" AdminDistrict="WA" Locality="Redmond" />

<ConfidenceFilter MinimumConfidence="High" />

</GeocodeRequest>

<GeocodeResponse DisplayName="16552 NE 74th St, Redmond, WA 98052-7804" EntityType="Address" Confidence="High" StatusCode="Success">

<Address AddressLine="16552 NE 74th St" AdminDistrict="WA" CountryRegion="United States" FormattedAddress="16552 NE 74th St, Redmond, WA 98052-7804" Locality="Redmond" PostalCode="98052-7804" />

<InterpolatedLocation Latitude="47.670211" Longitude="-122.119581" />

</GeocodeResponse>

</GeocodeEntity>

<GeocodeEntity Id="003"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US" Query="Seattle Space Needle" />

<GeocodeResponse DisplayName="Space Needle, WA" EntityType="LandmarkBuilding" Confidence="High" StatusCode="Success">

<Address AdminDistrict="Washington" CountryRegion="United States" FormattedAddress="Space Needle, WA" Locality="Seattle" />

<RooftopLocation Latitude="47.620495" Longitude="-122.34931" />

</GeocodeResponse>

</GeocodeEntity>

<GeocodeEntity Id="005"

xmlns="http://schemas.microsoft.com/search/local/2010/5/geocode">

<GeocodeRequest Culture="en-US">

<Address AddressLine="W Jefferson Blvd" AdminDistrict="CA" Locality="Los Angeles" PostalCode="90007" />

</GeocodeRequest>

<GeocodeResponse DisplayName="W Jefferson Blvd, Los Angeles, CA 90007" EntityType="RoadBlock" Confidence="High" StatusCode="Success">

<Address AddressLine="W Jefferson Blvd" AdminDistrict="CA" CountryRegion="United States" FormattedAddress="W Jefferson Blvd, Los Angeles, CA 90007" Locality="Los Angeles" PostalCode="90007" />

<InterpolatedLocation Latitude="34.0236140484618" Longitude="-118.28398661223" />

</GeocodeResponse>

</Geo