如何根据Power BI上的国家/地区名称查找国家/地区纬度?

问题描述 投票:1回答:1

我想找到国家纬度,希望能在Power BI上显示世界地图中的国家。

enter image description here

[请向我建议在PowerBI或PowerBI工具上可用的API上查找经纬度长的过程。

powerbi visualization latitude-longitude powerbi-desktop custom-function
1个回答
1
投票

首先,我们必须使用任何API服务来获取经纬度

创建bingmapsportal帐户

这里我使用的是Microsoft bing maps API服务,如果您还没有的话,请转到BingMapsPortal帐户到SignUP帐户enter image description here

SingUp之后,我们将登录,它将重定向到仪表板

enter image description here

生成密钥进入信息中心页面后,我们必须生成密钥以使用静态API服务

enter image description here准备好密钥后,请参考文档以找到api以根据给定的国家/地区获取经纬度和经度。

enter image description here

我们在下面使用给定url以xml格式获取经纬度

http://dev.virtualearth.net/REST/v1/Locations/india?o=xml&key=AjvYaTSLr8dsu4eqeDt0OigOZ_xuTkdVMUQCDMc0gcDPm

使用virtualearth API服务获取纬度和经度的位置一旦数据可用,我们就必须将其转换为表格形式enter image description here

创建调用自定义功能如果需要获取多个国家/地区的信息中心,则必须编写自定义调用函数(如下所示)并保存。enter image description here

= (location) =>

let
    Source = Xml.Tables(Web.Contents("http://dev.virtualearth.net/REST/v1/Locations/"&location&")?o=xml&key=AjvYaTSLr8dsu4eqeDt0OigOZ_xuTkdVMUQCDMc0gcDPmj2m57iWiwasSDZSCoNG")),
    #"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],
    #"Expanded Location" = Table.ExpandTableColumn(Resources, "Location", {"Name", "Point", "BoundingBox", "EntityType", "Address", "Confidence", "MatchCode", "GeocodePoint"}, {"Location.Name", "Location.Point", "Location.BoundingBox", "Location.EntityType", "Location.Address", "Location.Confidence", "Location.MatchCode", "Location.GeocodePoint"}),
    #"Location Point" = #"Expanded Location"{0}[Location.Point],
    #"Changed Type2" = Table.TransformColumnTypes(#"Location Point",{{"Latitude", type number}, {"Longitude", type number}})
in
    #"Changed Type2"

长时间使用lat以可视化地图通过在表格中创建新的自定义列,使用该自定义调用函数来获取多个纬度

enter image description here稍后我们必须将嵌入式表数据转换为列数据

enter image description here

为了显示国家(地区)并在没有鼠标悬停的情况下计算图例,我们创建了自定义图例列使用以下查询

语法:

State Count COLUMN = 'Table'[State]&" - "&CALCULATE(SUM('Table'[Count]), ALLEXCEPT('Table', 'Table'[State]))

enter image description here表格中的数据准备好后,我们必须将适当的值拖放到位置,图例和值上。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.