Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Bing API Geocode by Country only gives multiple results

Hi,

I am using Bing API to get Latitude and Longitude of Country only and It seems to loop through every possible region. I based my  api call off https://sqldusty.com/2016/04/26/power-bi-and-the-bing-maps-api/

The Country column is from my table, I don't understand why I am getting multiple results?

If anyone could kindly assist that would be most helpful.

Example:

The only parameter "country" so I figured that I could use "countryRegion" in my code. Here is the code:

 

 

let PointLookup = (country as text) =>

let
    Source = Xml.Tables(Web.Contents("http://dev.virtualearth.net/REST/v1/Locations/countryRegion="&country&"?o=xml&key=2D7Fw69q3CPBOs815sRV~")),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Copyright", type text}, {"BrandLogoUri", type text}, {"StatusCode", Int64.Type}, {"StatusDescription", type text}, {"AuthenticationResultCode", type text}, {"TraceId", type text}}),
    #"Expanded ResourceSets" = Table.ExpandTableColumn(#"Changed Type", "ResourceSets", {"ResourceSet"}, {"ResourceSets.ResourceSet"}),
    #"Expanded ResourceSets.ResourceSet" = Table.ExpandTableColumn(#"Expanded ResourceSets", "ResourceSets.ResourceSet", {"EstimatedTotal", "Resources"}, {"ResourceSets.ResourceSet.EstimatedTotal", "ResourceSets.ResourceSet.Resources"}),
    #"Expanded ResourceSets.ResourceSet.Resources" = Table.ExpandTableColumn(#"Expanded ResourceSets.ResourceSet", "ResourceSets.ResourceSet.Resources", {"Location"}, {"ResourceSets.ResourceSet.Resources.Location"}),
    #"Expanded ResourceSets.ResourceSet.Resources.Location" = Table.ExpandTableColumn(#"Expanded ResourceSets.ResourceSet.Resources", "ResourceSets.ResourceSet.Resources.Location", {"Name", "Point", "BoundingBox", "EntityType", "Address", "Confidence", "MatchCode", "GeocodePoint"}, {"ResourceSets.ResourceSet.Resources.Location.Name", "ResourceSets.ResourceSet.Resources.Location.Point", "ResourceSets.ResourceSet.Resources.Location.BoundingBox", "ResourceSets.ResourceSet.Resources.Location.EntityType", "ResourceSets.ResourceSet.Resources.Location.Address", "ResourceSets.ResourceSet.Resources.Location.Confidence", "ResourceSets.ResourceSet.Resources.Location.MatchCode", "ResourceSets.ResourceSet.Resources.Location.GeocodePoint"}),
    #"Expanded ResourceSets.ResourceSet.Resources.Location.GeocodePoint" = Table.ExpandTableColumn(#"Expanded ResourceSets.ResourceSet.Resources.Location", "ResourceSets.ResourceSet.Resources.Location.GeocodePoint", {"Latitude", "Longitude", "CalculationMethod", "UsageType"}, {"ResourceSets.ResourceSet.Resources.Location.GeocodePoint.Latitude", "ResourceSets.ResourceSet.Resources.Location.GeocodePoint.Longitude", "ResourceSets.ResourceSet.Resources.Location.GeocodePoint.CalculationMethod", "ResourceSets.ResourceSet.Resources.Location.GeocodePoint.UsageType"})
in
    #"Expanded ResourceSets.ResourceSet.Resources.Location.GeocodePoint"

in PointLookup

 

 

 

2 Replies

  • The other entries are cities/towns/villages that happen to have the same name as a country.

    • Anonymous's avatar
      Anonymous
      Not applicable

      I understand, I thought "CountryRegion" would just bring the country name but it looks like it's finding more than that. I tried the google api but now you need a subsciption so now trying with Bing.