我正在处理一个项目,在那里我获取设备位置并找到附近的标记。我无法在网上找到任何方法将我的位置转换为 Geopoint 。
$ ./sigtest
Blocking SIGHUP
Sleeping <-- SIGHUP sent from another terminal here but blocked
Unblocking SIGHUP
HUP 1 <-- Signal sent earlier now delivered and handled
Sleeping again
HUP 1 <-- Further signals sent are all handled
HUP 1
HUP 1
^C
我尝试了这个代码:
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);
}
但它在Visual Studio 2015 RC上说 Coordinate.Longitude.get已过时。
答案 0 :(得分: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 + "'>";
}