當前位置: 首頁>>代碼示例>>Java>>正文


Java Location.convert方法代碼示例

本文整理匯總了Java中android.location.Location.convert方法的典型用法代碼示例。如果您正苦於以下問題:Java Location.convert方法的具體用法?Java Location.convert怎麽用?Java Location.convert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.location.Location的用法示例。


在下文中一共展示了Location.convert方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createMockLocation

import android.location.Location; //導入方法依賴的package包/類
private Location createMockLocation() {
    String longitudeString = longitudeInput.getText().toString();
    String latitudeString = latitudeInput.getText().toString();

    if (!longitudeString.isEmpty() && !latitudeString.isEmpty()) {
        double longitude = Location.convert(longitudeString);
        double latitude = Location.convert(latitudeString);

        Location mockLocation = new Location("flp");
        mockLocation.setLatitude(latitude);
        mockLocation.setLongitude(longitude);
        mockLocation.setAccuracy(1.0f);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
        }
        mockLocation.setTime(new Date().getTime());
        return mockLocation;
    } else {
        throw new IllegalArgumentException();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:MockLocationsActivity.java

示例2: convert

import android.location.Location; //導入方法依賴的package包/類
private String convert(double latitude, double longitude) {
    StringBuilder builder = new StringBuilder();


    String latitudeDegrees = Location.convert(Math.abs(latitude), Location.FORMAT_SECONDS);
    String[] latitudeSplit = latitudeDegrees.split(":");
    builder.append(latitudeSplit[0]);
    builder.append("°");
    builder.append(latitudeSplit[1]);
    builder.append("'");
    builder.append(latitudeSplit[2]);
    builder.append("\"");
    if (latitude < 0) {
        builder.append(" S");
    } else {
        builder.append(" N");
    }
    builder.append("\n");


    String longitudeDegrees = Location.convert(Math.abs(longitude), Location.FORMAT_SECONDS);
    String[] longitudeSplit = longitudeDegrees.split(":");
    builder.append(longitudeSplit[0]);
    builder.append("°");
    builder.append(longitudeSplit[1]);
    builder.append("'");
    builder.append(longitudeSplit[2]);
    builder.append("\"");
    if (longitude < 0) {
        builder.append(" W");
    } else {
        builder.append(" E");
    }
    return builder.toString();
}
 
開發者ID:rahul051296,項目名稱:quake-alert-android-app,代碼行數:36,代碼來源:QuakeDetailsActivity.java

示例3: convertLocation

import android.location.Location; //導入方法依賴的package包/類
public static String convertLocation(final Resources res, final double coordinate, final boolean latitude)
{
    final String rawStr = Location.convert(coordinate, Location.FORMAT_MINUTES);
    //[+-]DDD:MM.MMMMM - FORMAT_MINUTES
    final String[] split = rawStr.split(":");
    final String direction;
    float min = 0f;


    //noinspection EmptyCatchBlock
    try
    {
        split[1] = split[1].replace(",",".");
        min = Float.parseFloat(split[1]);
    }
    catch (NumberFormatException e)
    {
    }
    
    if (latitude)
    {
        if (coordinate >= 0)
            direction = res.getString(R.string.test_location_dir_n);
        else
            direction = res.getString(R.string.test_location_dir_s);
    }
    else if (coordinate >= 0)
        direction = res.getString(R.string.test_location_dir_e);
    else
        direction = res.getString(R.string.test_location_dir_w);
    return String.format("%s %s°%.3f'", direction, split[0].replace("-", ""), min);
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:33,代碼來源:Helperfunctions.java


注:本文中的android.location.Location.convert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。