I write a location SDK, and the SDK produces android.location.Location
instance. When the user calls the Location.toString()
method to get readable text.
In the Location.toString
method, I find code like below
@Override
public String toString() {
StringBuilder s = new StringBuilder();
s.append("Location[");
s.append(mProvider);
s.append(String.format(" %.6f,%.6f", mLatitude, mLongitude));
if (hasAccuracy()) s.append(String.format(" hAcc=%.0f", mHorizontalAccuracyMeters));
else s.append(" hAcc=???");
if (mTime == 0) {
s.append(" t=?!?");
}
if (mElapsedRealtimeNanos == 0) {
s.append(" et=?!?");
} else {
s.append(" et=");
TimeUtils.formatDuration(mElapsedRealtimeNanos / 1000000L, s);
}
if (hasAltitude()) s.append(" alt=").append(mAltitude);
if (hasSpeed()) s.append(" vel=").append(mSpeed);
if (hasBearing()) s.append(" bear=").append(mBearing);
if (hasVerticalAccuracy()) s.append(String.format(" vAcc=%.0f", mVerticalAccuracyMeters));
else s.append(" vAcc=???");
if (hasSpeedAccuracy()) s.append(String.format(" sAcc=%.0f", mSpeedAccuracyMetersPerSecond));
else s.append(" sAcc=???");
if (hasBearingAccuracy()) s.append(String.format(" bAcc=%.0f", mBearingAccuracyDegrees));
else s.append(" bAcc=???");
if (isFromMockProvider()) s.append(" mock");
if (mExtras != null) {
s.append(" {").append(mExtras).append('}');
}
s.append(']');
return s.toString();
}
My subclass implemention is
@Override
public String toString() {
String superString = super.toString();
return "ErrorCode[" + mErrorCode + "]," +
"FromCached[" + mFromCache + "]," +
superString;
}
result
ErrorCode[0],FromCached[false], Location[network "31******,114****** acc=559 et=+1d19h24m40s624ms]"
what latitude
and longitude
may produce the weird result?
I tried Double.NaN
, Double.POSITIVE_INFINITY
, Double.MIN_VALUE
, but I cannot get this strange result.
More of a guess: you are probably looking at the wrong toString()
implementation.
It might be that your actual Location is of a subclass of that. One that is concerned about "privacy" and therefore masks part of that location string.
That is something that is very common: you want to ensure that sensitive information isn't going directly into logs or trace files. So you write a small wrapper that well, masks essential parts of the output, for example using * characters.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.