Hi @hhooi
For getting Langitude and Latitued based on Country and City using Bing APi, you can follow below steps.
- Go to https://www.bingmapsportal.com/
- Create an Account
- Go to My Account- My Keys - Create a New Key and Copy it.
- Once you have generated key, create an APi Query like below and use as a Web Source in Power BI.
http://dev.virtualearth.net/REST/v1/Locations?countryRegion=India&locality=Delhi&o=xml&key=**YourKey**
As you are looking for getting details for multiple country and cities, I have created a Function in Power BI.
let fnAddress = (Country as text,City as text) as table =>
let
BingKey = "AhVzYbelYPyvqADPMu7I_QWPs1vJVCkmpopoCuM0UQSUJ7Uu4FUhBFj2nzeezvZX",
Source = Xml.Tables(Web.Contents("http://dev.virtualearth.net/REST/v1/Locations?countryRegion="&Country&"&locality="&Country&"&o=xml&key="&BingKey&"")),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Copyright", type text}, {"BrandLogoUri", type text}, {"StatusCode", Int64.Type}, {"StatusDescription", type text}, {"AuthenticationResultCode", type text}, {"TraceId", type text}}),
ResourceSets = #"Changed Type"{0}[ResourceSets],
ResourceSet = ResourceSets{0}[ResourceSet],
Resources = ResourceSet{0}[Resources],
Location = Resources{0}[Location],
Point = Location{0}[Point],
#"Changed Type3" = Table.TransformColumnTypes(Point,{{"Latitude", type number}, {"Longitude", type number}})
in
#"Changed Type3"
in fnAddress
Now, we can call this function in your source by passing Country and City as value. This will return Latitude and Longitude for all. See sample below.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8sxLyUxU0lFySc3JyFSK1YlWCg0Gcv1SyyPzi7IRAs6JOZlp+UV5QMWxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Country = _t, City = _t]),
Custom1 = Table.AddColumn(Source,"Address",each GetLocation([Country],[City])),
#"Expanded Address" = Table.ExpandTableColumn(Custom1, "Address", {"Latitude", "Longitude"}, {"Address.Latitude", "Address.Longitude"})
in
#"Expanded Address"
EDNA_BingAPi_Solution.pbix (25.9 KB)
Thanks
Ankit J