Windows 8 如何从Windows 8 Metro Bing地图应用程序获取纬度和经度
如何从我点击/点击地图的位置获取纬度和经度 我发现了使用GeoCoordinate类的示例,但它是Win7 mobile的示例,Win8 Metro中不存在此类 我找到了Geocoordinate类,但它完全不同,而且我无法像示例中那样将我的地图转换为此类 我的Win 7样本如下所示Windows 8 如何从Windows 8 Metro Bing地图应用程序获取纬度和经度,windows-8,microsoft-metro,bing-maps,bing-api,Windows 8,Microsoft Metro,Bing Maps,Bing Api,如何从我点击/点击地图的位置获取纬度和经度 我发现了使用GeoCoordinate类的示例,但它是Win7 mobile的示例,Win8 Metro中不存在此类 我找到了Geocoordinate类,但它完全不同,而且我无法像示例中那样将我的地图转换为此类 我的Win 7样本如下所示 Point p = e.GetPosition(this.MapMain); GeoCoordinate geo = new GeoCoordinate(); geo = MapMain.ViewportPoint
Point p = e.GetPosition(this.MapMain);
GeoCoordinate geo = new GeoCoordinate();
geo = MapMain.ViewportPointToLocation(p);
到目前为止,我已经创建了一个新项目,添加了bing地图并设置了点击操作。但是我不知道,也找不到任何地方如何基于点击获取坐标。试试这个:
Point p = e.GetPosition(this.MainMap);
Location location = new Location();
MainMap.TryPixelToLocation(p, out location);
位置变量将具有纬度和经度值。首先,为click event添加一个事件侦听器: Microsoft.Maps.Events.addHandler(映射“单击”,映射单击) 然后在事件处理程序中: 函数映射单击(e){
}不要看metro的windows 7示例,它非常不同。这里有windows 8地理位置示例:thx我会尽快检查它们
if (e.targetType == "map") {
//Get x and y
var point = new Microsoft.Maps.Point(e.getX(), e.getY());
//Convert map point to location
var location = e.target.tryPixelToLocation(point);
console.log(location.longitude);
console.log(location.latitude);
}
// --------- HTML/JS --------------
var mapCenter = map.getCenter();
var pos = map.tryPixelToLocation(new Microsoft.Maps.Point(location.clientX, location.clientY), Microsoft.Maps.PixelReference.control);
// --------- C# -------------------
Geolocator geolocator = new Geolocator();
var pos = await geolocator.GetGeopositionAsync();
Location location = new Location(pos.Coordinate.Latitude, pos.Coordinate.Longitude);