2015-05-04 161 views
0

我正在处理一个项目,在该项目中获取设备位置并找到附近的标记。我无法在网上找到任何方式将我的位置转换为地理点获取设备位置并在地图上设置位置

public async void GetPosition() { 
    Geolocator geolocator = new Geolocator { DesiredAccuracyInMeters = 0 }; 
    Geoposition geoposition = await geolocator.GetGeopositionAsync(); 

    // Needs to be converted to Geopoint 
    // Call UpdateLocationData 
} 

public async void UpdateLocationData(Geopoint geopoint) { 
    await MapControl1.TrySetViewAsync(geopoint); 
} 

我想这个代码,我发现:

// Reverse Geocoding 
BasicGeoposition myLocation = new BasicGeoposition { 
    Longitude = position.Coordinate.Longitude, 
    Latitude = position.Coordinate.Latitude 
}; 

Geopoint pointToReverseGeocode = new Geopoint(myLocation); 

但它说,Coordinate.Longitude.get上的Visual Studio 2015年RC过时

+0

上'坐标的['Point'](https://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geocoordinate.point.ASPx)属性'返回一个'Geopoint'。 – Johnbot

+0

@Johnbot geoposition.Coordinate.Point?该死的,我会尽快查看是否正确。 – Kenny

回答

1

这是一个朋友,我放在一起使用JavaScript地理定位。

function getLocation() 
{ 
//Check for geolocation support in browser 
if (navigator.geolocation) { 
    //getCurrentPosition(function for success, function for error); 
    //getCurrentPosition creates a variable named position which has several properties 
    navigator.geolocation.getCurrentPosition(displayLocation, displayError, {maximumAge:600000, timeout:5000, enableHighAccuracy: true}); 
} else { 
    //Statement for testing else statement and error handling 
    document.getElementById('coordinates').innerHTML = "Browser unable to support geolocation."; 
} 
} 

//The argument for displayLocation is a variable created by getCurrentLocation 
function displayLocation(position) 
{ 
//Variables to track position 
var lati = position.coords.latitude; 
var longi = position.coords.longitude; 
//If getCurrentPosition is successful/true 
alert("Your position has been identified."); 
//Displays coordinates 
document.getElementById('coordinates').innerHTML = "Latitude: " + lati + " | Longitude: " + longi; 
//Displays coordinates on map 
showMap(position); 
} 

function displayError() 
{ 
//If getCurrentPosition fails/false 
alert("Unable to locate your position."); 
document.getElementById('coordinates').innerHTML = "Unable to locate your position."; 
} 

function showMap(position) 
{ 
//Variables to track position 
var lati = position.coords.latitude; 
var longi = position.coords.longitude; 
var imageURL= "http://maps.googleapis.com/maps/api/staticmap?center=" + lati + "," + longi + "&zoom=14&size=500x375&sensor=false"; 
document.getElementById('map').innerHTML = "<img src='" + imageURL + "'>"; 
} 
+0

我在问自己为什么地狱的位置。坐标是过时的,我需要找到其他方式,但微软文档是没用的。 – Kenny

+0

我应该为选项单独添加第三个参数,但是...我不确定是否我做的选项的方式将工作,我还没有测试该部分,因为我刚刚添加它。但其余的工作正常。 – MrEhawk82