Skip to content
Advertisement

Inaccurate resulte from Bing Maps Geocode Dataflow

I am using a Python POST request to geocode the addresses of my company’s branches, but I’m getting wildly inaccurate results.

I looked at this answer, but the problem is that some results aren’t being processed. My problem is different in that all of my results are inaccurate, even ones with Confidence="High". And I do have an enterprise account.

Here’s the documentation that shows how to create a geocode Job and upload data:
https://learn.microsoft.com/en-us/bingmaps/spatial-data-services/geocode-dataflow-api/create-a-geocode-job-and-upload-data

here’s a basic version of my code to upload:

import requests    

SDS_Geocode_URL = "https://spatial.virtualearth.net/REST/v1/dataflows/geocode?"

geocode_post_vars = {
    "input": "xml",
    "output": "json",
    "content-type": "application/xml",
    "key": Bing_key,
}

geocode_Post_URL = (
    SDS_Geocode_URL
    + urllib.parse.urlencode(geocode_post_vars)
    + "&dataLocation="
    + "https://account-name.blob.core.windows.net/myDataFile.xml"
)

r = requests.post(geocode_Post_URL)

And once the data is geocoded, I use a GET request to get the geocoded XML

geocode_Results = requests.get(
    "https://spatial.virtualearth.net/REST/v1/dataflows/Geocode/"
    + jobID
    + "/output/succeeded?key=" + Bing_key
)

print(geocode_Results.text)

And I get results like this:

<GeocodeEntity Id="12040000">
    <GeocodeRequest Culture="en-US" IncludeNeighborhood="true" Query="Rush Truck Center - Los Angeles" IncludeQueryParse="true">
        <Address AddressLine="8830 Slauson Ave, Pico Rivera, CA 90660" AdminDistrict="California" CountryRegion="US" Locality="Pico Rivera" PostalCode="90660" />
    </GeocodeRequest>
    <GeocodeResponse Name="Los Angeles, CA" EntityType="PopulatedPlace" Confidence="High" MatchCodes="UpHierarchy">
        <Address AdminDistrict="CA" CountryRegion="United States" AdminDistrict2="Los Angeles County" FormattedAddress="Los Angeles, CA" Locality="Los Angeles" />
        <GeocodePoint CalculationMethod="Rooftop" Latitude="34.0522384643555" Longitude="-118.243347167969" Type="Point" UsageTypes="Display" />
        <QueryParseValue Property="Locality" Value="Los Angeles" />
        <BoundingBox SouthLatitude="33.6968193054199" WestLongitude="-118.683807373047" NorthLatitude="34.3506469726563" EastLongitude="-118.138854980469" />
        <Point Latitude="34.0522384643555" Longitude="-118.243347167969" />
    </GeocodeResponse>
    <StatusCode>Success</StatusCode>
    <TraceId>#######</TraceId>
</GeocodeEntity>

In my Geocode request, I have a specific address and company branch name (redacted for this question). Additionally, I have added city, state, country, and zipcode attributes exactly as stated in the documents.

Even with all that information, the geocoded response data returns is no more granular than general city of Los Angeles, and the Lat/Long coordinates for the city, not the address I provided (for the record, it’s ten miles away from where it should be).

Also, when I upload the XML file manually through the Bing Maps portal, it’s perfectly accurate. Am I formatting the request wrong, or is this a Bing problem?

Advertisement

Answer

I see several issues in your request data:

  • The “query” value you are passing in is a combination of a point of interest name and a location. Geocoders only work with addresses. So in this case the point of interest name is being dropped and only “Los Angeles” is being used by the geocoder, thus the result.
  • You are mixing two different geocode query types into a single query. Either use just “query” or just the individual address parts (AddressLine, Locality, AdminDistrict, CountryRegion, PostalCode). In this case, the “query” value is being used an everything else in being ignored, using the individual address parts will be much more accurate than your query.
  • You are passing in the full address into the AddressLine field. That should only be the street address (i.e. “8830 Slauson Ave”).

Here is a modified version of the request that will likely return the information you are expecting:

<GeocodeRequest Culture="en-US" IncludeNeighborhood="true" IncludeQueryParse="true">
        <Address AddressLine="8830 Slauson Ave" AdminDistrict="California" CountryRegion="US" Locality="Pico Rivera" PostalCode="90660" />
    </GeocodeRequest>
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement