2015-05-04 112 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