本文整理匯總了Java中android.location.Location.getExtras方法的典型用法代碼示例。如果您正苦於以下問題:Java Location.getExtras方法的具體用法?Java Location.getExtras怎麽用?Java Location.getExtras使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.location.Location
的用法示例。
在下文中一共展示了Location.getExtras方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCurrent
import android.location.Location; //導入方法依賴的package包/類
@Override
public String getCurrent() {
if (infoCollector != null) {
String locationString = null;
final Location loc = infoCollector.getLocationInfo();
if (loc != null) {
final int satellites;
if (loc.getExtras() != null) {
satellites = loc.getExtras().getInt("satellites");
} else {
satellites = 0;
}
locationString = Helperfunctions.convertLocationAccuracy(context.getResources(),
loc.hasAccuracy(), loc.getAccuracy(), satellites);
locationString += " (" + Helperfunctions.getAgeString(loc) + ")";
} else {
locationString = context.getString(R.string.not_available);
}
return locationString;
}
return null;
}
示例2: appendData
import android.location.Location; //導入方法依賴的package包/類
/** Add another track point to the GPX file.
*
* For more information and examples about the GPX format, see https://de.wikipedia.org/wiki/GPS_Exchange_Format.
*
* @param location The data to append as a track point
*/
void appendData(Location location){
// 1: latitude, 2: longitude, 3: attributes
final String TRACKPOINT_FORMAT = "\t\t<trkpt lat=\"%1$s\" lon=\"%2$s\">\n%3$s\t\t</trkpt>\n";
// attributes
final String ALTITUDE_FORMAT = "\t\t\t<ele>%1$s</ele>\n";
final String TIME_FORMAT = "\t\t\t<time>%1$s</time>\n";
final String NUMBER_OF_SAT_FORMAT = "\t\t\t<sat>%1$s</sat>\n";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
String time = dateFormat.format(location.getTime());
StringBuilder attributes = new StringBuilder();
attributes.append(String.format(ALTITUDE_FORMAT, location.getAltitude()));
attributes.append(String.format(TIME_FORMAT, time));
Bundle extras = location.getExtras();
if((extras != null) && (extras.getString("satellites") != null)){
String numberOfSatellites = extras.getString("satellites");
attributes.append(String.format(NUMBER_OF_SAT_FORMAT, numberOfSatellites));
}
// TODO: include "horizontal dilution of precision" as an attribute
// TODO: include speed uncertainty as an attribute [NOT IN THE STANDARD!]
String trackpoint = String.format(TRACKPOINT_FORMAT, location.getLatitude(), location.getLongitude(), attributes);
file.write(trackpoint);
}