Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Get longitude and latitude with public place names - Bing Maps API

Hello,

 

I have a list of public places, for example store names, hospital names, government buildings.

 

I would like to get the latitude and longitude from these names. I have tried this tutorial https://www.youtube.com/watch?v=YxwU5UubWjI but instead of addresses I put in the store names + city + country but the longitude and latitude that comes out is incorrect.

 

I tried to input the same store names + city + country into Bing Maps itself and it works just fine:

 

phuogh_0-1632990738328.png

phuogh_1-1632990758851.png

 Is this possible to achieve?

 

Thank you beforehands 🙂

3 REPLIES 3
rouvenor
New Member

did you ever find a solution?

v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

I think the first way is the workaround. Is your issue that when you invoke custom function, you will get incorrect result? There may be some differencet locations with same name in same country and city. You can add more details in your location.

If you still want to get data by Way 2, please refer to the post as below and try this code.

let

    FindLatLong = (location) =>

let
    Source = Xml.Tables(Web.Contents("http://dev.virtualearth.net/REST/v1/Locations/"&location&"?o=xml&key=XXX",
        [ManualStatusHandling={404}])),
        GetMetadata = Value.Metadata(Source),
        GetResponseStatus = GetMetadata[Response.Status], 
        Output = if GetResponseStatus=404 then "Error!" else Source,
        #"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],
        #"Changed Type1" = Table.TransformColumnTypes(ResourceSet,{{"EstimatedTotal", Int64.Type}}),
        Resources = #"Changed Type1"{0}[Resources],
        Location = Resources{0}[Location],
        #"Changed Type2" = Table.TransformColumnTypes(Location,{{"Name", type text}, {"EntityType", type text}, {"Confidence", type text}, {"MatchCode", type text}}),
        Point = #"Changed Type2"{0}[Point],
        #"Changed Type3" = Table.TransformColumnTypes(Point,{{"Latitude", type number}, {"Longitude", type number}})
in
    #"Changed Type3"

in

    FindLatLong

For reference: Power Query Function Error Bing Maps API Token Literal Expected Error when 404 is returned

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

I have found the Bing Maps API also offers the finding of such places using LocalSearch.

 

Source = Json.Document(Web.Contents("https://dev.virtualearth.net/REST/v1/LocalSearch/",[RelativePath=NameOfLocation,

    Query=[
         userMapView="xxxx,yyyy,zzzz,wwww",
         key="xxxxxxxxxx"
    ]
]),TextEncoding.Utf8),

 

The error is 404 Not Found

 

DataSource.Error: Web.Contents failed to get contents from 'https://dev.virtualearth.net/REST/v1/LocalSearch/Name%20Of%20Place?userMapView=xxxx%2Cyyyy%2Czzzz%2w...' (404): Not Found

 

How can I fix this issue?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.