本文整理汇总了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);
}