зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 30b340a71112. r=me
This commit is contained in:
Родитель
7b2c2dd576
Коммит
07980c9f0f
|
@ -789,12 +789,6 @@ nsGeolocationService::Observe(nsISupports* aSubject,
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsGeolocationService::Update(nsIDOMGeoPosition *aSomewhere)
|
nsGeolocationService::Update(nsIDOMGeoPosition *aSomewhere)
|
||||||
{
|
{
|
||||||
// here we have to determine this aSomewhere is a "better"
|
|
||||||
// position than any previously recv'ed.
|
|
||||||
|
|
||||||
if (!IsBetterPosition(aSomewhere))
|
|
||||||
return NS_OK;
|
|
||||||
|
|
||||||
SetCachedPosition(aSomewhere);
|
SetCachedPosition(aSomewhere);
|
||||||
|
|
||||||
for (uint32_t i = 0; i< mGeolocators.Length(); i++) {
|
for (uint32_t i = 0; i< mGeolocators.Length(); i++) {
|
||||||
|
@ -803,92 +797,6 @@ nsGeolocationService::Update(nsIDOMGeoPosition *aSomewhere)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRBool
|
|
||||||
nsGeolocationService::IsBetterPosition(nsIDOMGeoPosition *aSomewhere)
|
|
||||||
{
|
|
||||||
if (!aSomewhere) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mProviders.Count() == 1 || !mLastPosition) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMGeoPositionCoords> coords;
|
|
||||||
mLastPosition->GetCoords(getter_AddRefs(coords));
|
|
||||||
if (!coords) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
double oldAccuracy;
|
|
||||||
nsresult rv = coords->GetAccuracy(&oldAccuracy);
|
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
double oldLat, oldLon;
|
|
||||||
rv = coords->GetLongitude(&oldLon);
|
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
rv = coords->GetLatitude(&oldLat);
|
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
aSomewhere->GetCoords(getter_AddRefs(coords));
|
|
||||||
if (!coords) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
double newAccuracy;
|
|
||||||
rv = coords->GetAccuracy(&newAccuracy);
|
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
double newLat, newLon;
|
|
||||||
rv = coords->GetLongitude(&newLon);
|
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
rv = coords->GetLatitude(&newLat);
|
|
||||||
NS_ENSURE_SUCCESS(rv, false);
|
|
||||||
|
|
||||||
// Latitude and longitude is reported in degrees.
|
|
||||||
// However, it is easier to work in radian:
|
|
||||||
// see: http://en.wikipedia.org/wiki/Radian
|
|
||||||
double radsInDeg = M_PI / 180.0;
|
|
||||||
|
|
||||||
newLat *= radsInDeg;
|
|
||||||
newLon *= radsInDeg;
|
|
||||||
oldLat *= radsInDeg;
|
|
||||||
oldLon *= radsInDeg;
|
|
||||||
|
|
||||||
// WGS84 equatorial radius of earth = 6378137m
|
|
||||||
// http://en.wikipedia.org/wiki/WGS84
|
|
||||||
double radius = 6378137;
|
|
||||||
|
|
||||||
// We want to calculate the "Great Circle distance"
|
|
||||||
// between the point (lat1, lon1) and (lat2, lon2). We
|
|
||||||
// will use the spherical law of cosines to the triangle
|
|
||||||
// formed by our two points and the north pole.
|
|
||||||
//
|
|
||||||
// a = sin ( lat1 ) * sin ( lat2 ) + cos ( lat1 ) * cos (lat2) * cos (lon1 - lon2)
|
|
||||||
// R = radius of circle
|
|
||||||
// distance = arccos ( a ) * R
|
|
||||||
//
|
|
||||||
// http://en.wikipedia.org/wiki/Great-circle_distance
|
|
||||||
|
|
||||||
double delta = acos( (sin(newLat) * sin(oldLat)) +
|
|
||||||
(cos(newLat) * cos(oldLat) * cos(oldLon - newLon)) ) * radius;
|
|
||||||
|
|
||||||
// The threshold is when the distance between the two
|
|
||||||
// positions exceeds the worse (larger value) of the two
|
|
||||||
// accuracies.
|
|
||||||
double max_accuracy = NS_MAX(oldAccuracy, newAccuracy);
|
|
||||||
if (delta > max_accuracy)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// check to see if the aSomewhere position is more accurate
|
|
||||||
if (oldAccuracy >= newAccuracy)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
nsGeolocationService::SetCachedPosition(nsIDOMGeoPosition* aPosition)
|
nsGeolocationService::SetCachedPosition(nsIDOMGeoPosition* aPosition)
|
||||||
{
|
{
|
||||||
|
|
|
@ -121,7 +121,6 @@ public:
|
||||||
|
|
||||||
void SetCachedPosition(nsIDOMGeoPosition* aPosition);
|
void SetCachedPosition(nsIDOMGeoPosition* aPosition);
|
||||||
nsIDOMGeoPosition* GetCachedPosition();
|
nsIDOMGeoPosition* GetCachedPosition();
|
||||||
PRBool IsBetterPosition(nsIDOMGeoPosition *aSomewhere);
|
|
||||||
|
|
||||||
// Find and startup a geolocation device (gps, nmea, etc.)
|
// Find and startup a geolocation device (gps, nmea, etc.)
|
||||||
nsresult StartDevice();
|
nsresult StartDevice();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче