标签: android-gps

Android如何将纬度经度转换为Degree格式

我想转换纬度40.7127837,经度-74.0059413,并采用以下格式

N 40°42'46.0218"W 74°0'21.3876"

最好的方法是什么?

我尝试过像location.FORMAT_DEGREES,location.FORMAT_MINUTES和location.FORMAT_SECONDS这样的方法,但我不知道如何将它们转换为正确的格式.谢谢.

strLongitude = location.convert(location.getLongitude(), location.FORMAT_DEGREES);
strLatitude = location.convert(location.getLatitude(), location.FORMAT_DEGREES);
Run Code Online (Sandbox Code Playgroud)

java android google-maps latitude-longitude android-gps

8
推荐指数
2
解决办法
6130
查看次数

Android onLocationChanged location.getTime()返回错误的时间

我有一个三星Galaxy Tab答:我已经实现了android.location.LocationListeneronLocationChanged(Location location)被调用,这让我有点权的经度和纬度,但是,

问题是: location.getTime()给我错误的时间,它返回的时间接近30万密耳左右.应该是这样的1471243684497.

我不知道该怎么办.

GPSTracker类:

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

public class GPSTracker extends Service implements LocationListener
{
    //flag for GPS Status
    boolean isGPSEnabled = false;

    //flag for network status
    //boolean isNetworkEnabled = false;

    boolean canGetLocation = false;

    Location location;
    double latitude;
    double longitude;

    //The minimum distance to …
Run Code Online (Sandbox Code Playgroud)

android android-location android-gps

8
推荐指数
1
解决办法
1589
查看次数

onStatusChanged情况

我有一些怀疑onStatusChangedLocationListener类.

它知道它可以呈现三种状态:AVAILABLE,TEMPORARILY_UNAVAILABLEOUT_OF_SERVICE

  1. AVAILABLE出来的时候只得到触发TEMPORARILY_UNAVAILABLE?或者当GPS刚刚完成预热时?或者在第一次更新位置之前?

  2. 怎么样OUT_OF_SERVICE,什么时候被触发?就在之前onProviderDisabled

  3. 是否可以使用模拟器模拟这些事件(状态)?

android android-gps

8
推荐指数
1
解决办法
586
查看次数

在背景中获取准确的中间位置点,并计算Android中起始位置和结束位置的距离

关于这个主题可能有类似的问题,但我需要你对一些具体要求的想法和建议.

这是我的需要 - 我们正在开发一个跟踪用户旅行的应用程序.该应用程序将开始在后台收集该用户的位置,当用户从App.Background Service"开始"他的旅程时,将根据用户在特定持续时间内的移动来获取位置.当用户"从应用程序停止"他的行程时,我们正在计算用户在所有记录位置的帮助下行进的距离(使用Google距离计算API).该应用程序在理想情况下工作正常.但主要的挑战是 - 在某些情况下,我们无法获取用户的准确和精确位置.影响的场景是 - 没有互联网,2g/3g的数据计划,GPS没有返回准确数据的某些特定区域等.

lat-long数据不正确会导致跳闸距离和路线不正确.这是App的主要问题.

请问,任何人都可以建议最好的选择/建议吗?PS - 我们尝试过GPS,网络,FusedLocationProvider.

编辑2 -

我们已经在准确性和距离的基础上实现了逻辑.更接近点.而且刚刚从谷歌那里找到了一个有用的api来纠正一些与实际道路分散注意力的位置点.在此发布以供其他人参考......

来自Google的Snap to Roads Api

android android-location android-fusedlocation android-gps

8
推荐指数
1
解决办法
552
查看次数

SettingsClient的位置请求始终获得RESULT_CANCELED

在获取当前位置流时,我正在使用SettingsClient根据当前LocationRequest来检查是否满足位置设置。目前,我的优先级设置为HIGH_ACCURACY,这需要不惜一切代价启用GPS。

        fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
        settingsClient = LocationServices.getSettingsClient(this);
        locationRequest = LocationRequest.create()
                .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                .setInterval(500)
                .setFastestInterval(500);
        LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
        builder.addLocationRequest(locationRequest);
        locationSettingsRequest = builder.build();
Run Code Online (Sandbox Code Playgroud)

现在,当我调用给它提供侦听器的SettingsClient.checkLocationSettings()时,

settingsClient.checkLocationSettings(locationSettingsRequest)
                .addOnCompleteListener(this)
                .addOnFailureListener(this);
Run Code Online (Sandbox Code Playgroud)

它属于onFailure(),在这种情况下,github上的google官方示例采用以下方法;

检查在onFailure()中接收到的异常的状态码(如果它是LocationSettingsStatusCodes.RESOLUTION_REQUIRED),然后调用startResolutionForResult(),它允许我们启用GPS,这将等待使用onActivityResult的结果。

    @Override
    public void onFailure(@NonNull Exception e) {

        int statusCode = ((ApiException) e).getStatusCode();
        switch (statusCode) {
            case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:

                try {
                    // Show the dialog by calling startResolutionForResult(), and check the
                    // result in onActivityResult().
                    ResolvableApiException rae = (ResolvableApiException) e;
                    rae.startResolutionForResult(LocationActivity.this, REQUEST_CHECK_SETTINGS);
                } catch (IntentSender.SendIntentException sie) {
                    showLocationError();
                }
                break;
            case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: …
Run Code Online (Sandbox Code Playgroud)

android location google-play-services android-gps

8
推荐指数
1
解决办法
314
查看次数

上下文发生了变化,无法进行操作

我的应用程序使用两个独立的Process.我拥有所有的Services一个Process和所有其他组件在另一个Process.当我试图从获得lastKnownLocation LocationManger的时候Intent收到与行动public int onStartCommand(Intent intent, int flags, int startId)Activity,我得到了Location空,当我看到的LocationManager物体在其显示调试器Context has changed, operation is not possible.感谢帮助在此输入图像描述.以下是代码片段 -

@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        String action = intent.getAction();
        if (action != null) {
            if (action.equalsIgnoreCase(Synchronize.ACTION_UPDATE_LOCATION)) {
                Location location = getLastKnownLocation();
                if (location != null) {
                    new Synchronize(getApplicationContext()).
                            updateLocation(prefs.getInt(Utils.PROPERTY_USER_ID, 0),
                                    location.getLatitude(), location.getLongitude(),
                                    Utils.formatDateMilliSecondToUTC(location.getTime()));
                }
            } else if …
Run Code Online (Sandbox Code Playgroud)

android location android-gps

7
推荐指数
0
解决办法
810
查看次数

如何在启动应用程序时要求用户启用GPS?

private void turnGPSOn(){
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if(!provider.contains("gps")){ //if gps is disabled
    final Intent poke = new Intent();
    poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); 
    poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
    poke.setData(Uri.parse("3")); 
    sendBroadcast(poke);
}
}
Run Code Online (Sandbox Code Playgroud)

看到Logcat

04/20 17:35:26: Launching app
$ adb push F:\AndroidProject\Picker\app\build\outputs\apk\app-debug.apk /data/local/tmp/picker.novasyslabs.com.picker
$ adb shell pm install -r "/data/local/tmp/picker.novasyslabs.com.picker"
    pkg: /data/local/tmp/picker.novasyslabs.com.picker
Success


$ adb shell am start -n "picker.novasyslabs.com.picker/picker.novasyslabs.com.picker.SlashScreen" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 22502 on device sony-d2302-ZH80065A89
W/ResourceType: Found multiple library tables, ignoring...
W/ResourceType: Found multiple library tables, ignoring...
W/ResourceType: Found multiple library …
Run Code Online (Sandbox Code Playgroud)

android android-location android-gps

7
推荐指数
4
解决办法
1万
查看次数

在一段时间内让子区域为空?

下面是我的代码,我总是得到null subLocality...。

Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses  = geocoder.getFromLocation(latitude,longitude, 1);

String suburb = addresses.get(0).getSubLocality();
String state = addresses.get(0).getAdminArea();
String zip = addresses.get(0).getPostalCode();
String country = addresses.get(0).getCountryName();

Log.e("Log for data",""+suburb+" "+state+" "+zip+" "+country);
Run Code Online (Sandbox Code Playgroud)

以下是我的回复;

null Gujarat 380006 India
Run Code Online (Sandbox Code Playgroud)

gps android location android-gps

7
推荐指数
1
解决办法
335
查看次数

如何同步检索当前地理位置?

由于我们的应用程序的工作方式,我需要同步获取用户的当前位置。我们当前的实现使用com.google.android.gms.location.LocationListener来接收位置更新。问题是,我需要在尝试第一次调用之前更新位置服务器端,否则用户会得到错误的数据。

LocationServices.FusedLocationApi.getLastLocation() 不适合这个,因为a)它似乎总是返回null(无论出于何种原因)和b)我们已经保存了用户最后一个已知位置服务器端,因此检索最后一个已知位置并将其发送到服务器是多余的.

伪代码

//this is the first call I need to make
webservice.appStart(AppStartBody body);
//then I want to retrieve the current location and send it to the server
webservice.setGeoLocation(getCurrentLocation());
//finally, I retrieve the items on the server based on the location
webservice.getListItems();
Run Code Online (Sandbox Code Playgroud)

等待第一个位置更新事件是我想避免的一种可能性,因为我不知道它会在多长时间内触发,我可能不得不让我的用户在加载屏幕上停留很长时间,然后失去他们,因为没有人喜欢等待。

gps android android-fusedlocation android-gps

6
推荐指数
1
解决办法
1300
查看次数

RoboScript 无法在 Firebase Testlab 中单击“启用位置确定”按钮

我正在尝试在 Firebase TestLab 上使用 RoboScript 测试基于 Google 地图的 Android 应用程序。默认情况下,TestLab 设备上禁用位置。要启用它们,我们需要模拟单击系统提示上的“确定”按钮。但这种点击永远不会发生。您可以看到下面的屏幕截图。“确定”按钮永远不会被按下,流程将在此停止。

截屏

我检查了 RoboScript json 文件。Android studio 从未记录过“确定”按钮的点击。我尝试创建另一个元素,如下所示。但无法确定系统对话框的resourceId 应该是什么。

    {
        "eventType": "VIEW_CLICKED",
        "timestamp": 1512127956674,
        "replacementText": "",
        "actionCode": -1,
        "delayTime": 0,
        "canScrollTo": false,
        "elementDescriptors": [
          {
            "className": "android.widget.LinearLayout",
            "recyclerViewChildPosition": -1,
            "adapterViewChildPosition": -1,
            "groupViewChildPosition": 0,
            "resourceId": "com.entransys.parkeze:id/confirm_linear",
            "contentDescription": "",
            "text": ""
          },
          {
            "className": "android.support.v7.widget.ContentFrameLayout",
            "recyclerViewChildPosition": -1,
            "adapterViewChildPosition": -1,
            "groupViewChildPosition": 1,
            "resourceId": "android:id/content",
            "contentDescription": "",
            "text": ""
          },
          {
            "className": "android.support.v7.widget.FitWindowsLinearLayout",
            "recyclerViewChildPosition": -1,
            "adapterViewChildPosition": -1,
            "groupViewChildPosition": 0,
            "resourceId": "com.entransys.parkeze:id/action_bar_root",
            "contentDescription": "",
            "text": "" …
Run Code Online (Sandbox Code Playgroud)

android firebase android-gps

6
推荐指数
1
解决办法
655
查看次数