当我尝试使用地理定位服务找到自己时,我的位置不正确。我在13楼,所以我认为这可能是一个问题。我到外面去了一分钟,在地面测试它,并且它有效。所以,现在我试图找出一种方法来纠正海拔高度。我已经检查了所有问题和所有问题,但我发现任何足够接近的东西都无法帮助我。我尝试过highAccuracy方法,但没有任何结果。这是我的代码:
var you;
var directions;
var directionsService = new google.maps.DirectionsService();
var geocoder = new google.maps.Geocoder();
var pj = {
address: "57575 190th Street, Pacific Junction, IA 51561",
latitude: 41.018899,
longitude: -95.822685
};
var tifton = {
address: "267 Southwell Blvd, Tifton, GA 31794",
latitude: 31.417032,
longitude: -83.498785
};
var nlv = {
address: "4020 East Lone Mountain Road #105, North Las Vegas, NV 89030",
latitude: 36.228928,
longitude: -115.112426
};
//get the map that was clicked
$('.map').click(function(){
//determine which map it was that was clicked
var map = $(this).data('map');
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(successFunction, errorFunction, {'enableHighAccuracy':true,'timeout':10000,'maximumAge':0});
}
function successFunction(position){
var lat = position.coords.latitude;
var lng = position.coords.longitude;
switch(map){
case 'pj':
codeLatLng(lat, lng, pj['address']);
break;
case 'tifton':
codeLatLng(lat, lng, tifton['address']);
break;
case 'nlv':
codeLatLng(lat, lng, nlv['address']);
break;
}
}
function errorFunction(){
alert('Oops! It looks like the Geocoder service is down at the moment. Please try again later!');
}
});
function codeLatLng(lat, lng, loc){
var spot = new google.maps.LatLng(lat, lng);
geocoder.geocode({"location": spot}, function(results, status){
if(status == google.maps.GeocoderStatus.OK){
if(results[1]){
you = results[0].formatted_address;
alert(you);
var request = {
origin: you,
destination: loc,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status){
if(status == google.maps.DirectionsStatus.OK){
$('.modal-title').html("Directions to "+response['routes'][0]['legs'][0]['end_address']);
$('.modal-body').append('<p class="text-primary"><b>Estimated Travel Time: </b>'+response["routes"][0]["legs"][0]["duration"]["text"]+'</p>');
$('.modal-body').append('<p class="text-primary"><b>Estimated Distance: </b>'+response["routes"][0]["legs"][0]["distance"]["text"]+'</p>');
for(var i = 0; i < response['routes'][0]['legs'][0]['steps'].length; i++){
$('.modal-body').append('<p><span class="text-info">Step '+(i+1)+':</span> '+ response["routes"][0]["legs"][0]["steps"][i]["instructions"] + '</p>');
}
$('#map-directions').modal('show');
}
});
}else{
alert("No results found");
}
}else{
alert("Geocoder failed due to: " + status);
}
});
}
编辑:以下是已经发生的不同事情的摘要,
- PHONE:
- On wi-fi on the 13th floor of my building: Off by 2 city blocks
- On the cell network in my building: off by two miles and in the wrong state
- On the cell network outside: accurate anywhere
- PC:
- On wi-fi on the 13th floors: Accurate to the point
- On the LAN network: off my 1.5 miles southeast
所以说到了,如何让它一直准确?
有关如何分配高度变化的任何建议?非常感谢任何和所有的帮助!