LocationManagerAndroid上的API似乎对于仅需要偶尔粗略估计用户位置的应用程序来说有点痛苦.
我正在处理的应用程序本身并不是一个位置应用程序,但它确实需要获取用户的位置才能显示附近的商家列表.它不需要担心用户是否在移动或类似的东西.
这是我想做的事情:
ActivityX中需要它时,它将可用.看起来它应该不那么难,但在我看来,我必须启动两个不同的位置提供商(GPS和NETWORK)并管理每个生命周期.不仅如此,我还必须在多个活动中复制相同的代码以满足#2.我曾尝试过使用getBestProvider()过去将解决方案缩减为只使用一个位置提供商,但这似乎只能为您提供最好的"理论"提供商,而不是实际上会给您带来最佳结果的提供商.
有没有更简单的方法来实现这一目标?
我有一个程序,其中一个位置的纬度和经度值存储在我下载的数据库中.
我想得到这些坐标和我当前位置之间的距离.
Location类有一个简单的方法来查找两个Location对象之间的距离,所以我想我会用坐标创建一个Location对象,然后调用该方法.
是否有捷径可寻?而且,如果还有另一个可靠,相当简单的方程式,它不会使事情变得太混乱,那也会起作用.谢谢.
(android.location.Location)
为了工作,我的应用需要一个位置API.我打算使用Mapbox平台来定制它的设计(因为就我而言,谷歌地图不提供这种级别的定制).
文档说我们应该在构建位置应用时使用Google Play API:
Google Play服务位置API优先于Android框架位置API(android.location),作为向您的应用添加位置感知的一种方式.如果您当前正在使用Android框架位置API,强烈建议您尽快切换到Google Play服务位置API.
我的问题是:在GPS准确性方面,Google Play API是最有效的API吗?或者我应该使用LocationManager和LocationListener的方式吗?
我需要准确性.我应该使用哪一个?谢谢.
我想在谷歌地图上绘制路径.
基本上我在特定时间间隔后跟踪用户位置.当用户到达某个目的地时,我需要画出他到达目的地的路径.
它工作正常,但问题是它显示之字形路径.见下图.
我想要的是:
我想绘制一条正确的路径,然后跟踪我在跟踪期间得到的点.
我试过的
我搜索并找到了这个链接,我们可以通过最多8点来获取方向.这是Google地图的非商业用户允许的最高限额.有没有其他方法来实现这一目标.因为我在地图上画了很多分.
绘制折线的代码
private void drawPath() {
if (mMap != null)
mMap.clear();
int count = 0;
LatLng prev = null;
String[] mProjection = {LocTable.COLUMN_ID, LocTable.COLUMN_LONGITUDE, LocTable.COLUMN_LATITUDE};
String mSelectionClause = LocTable.COLUMN_ID + "> ?";
String[] mSelectionArgs = {"0"};
String mSortOrder = LocTable.COLUMN_ID;
Cursor mCursor = getContentResolver().query(
LocContentProvider.CONTENT_URI, // The content URI of the words table
mProjection, // The columns to return for each row
mSelectionClause, // Selection criteria
mSelectionArgs, // Selection criteria
mSortOrder);
if(mCursor …Run Code Online (Sandbox Code Playgroud) 为什么BroadcastReceiver触发多次.
我的示例项目如下面的代码
ANDROID MANIFEST
<receiver
android:name=".LocationProvideListener"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED"/>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
BBROADCAST RECEIVER
public class LocationProvideListener extends BroadcastReceiver {
private static final String TAG = "LocationProvideListener";
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().matches(LocationManager.PROVIDERS_CHANGED_ACTION))
{
// react on GPS provider change action
LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
boolean isNetwork = manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
boolean isGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
Log.e(TAG, "IsNetwork = " + (isNetwork ? "true" : "false"));
Log.e(TAG, "IsGPS = " + (isGPS ? "true" : …Run Code Online (Sandbox Code Playgroud) 表现:
<receiver android:name=".GpsLocationReceiver">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
BroadcastReceiver:
public class GpsLocationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "onReceive...");
if(intent.getAction().matches("android.location.PROVIDERS_CHANGED")) {
Log.d(TAG, "GPS provider changed...");
EventBus.getDefault().postLocal(intent.getAction());
}
}
}:
Run Code Online (Sandbox Code Playgroud) 我想在没有GPS且仅具有网络位置的模拟设备上测试我的应用。我已经为没有GPS的设备创建了硬件配置文件。
如何使用网络位置将LAT / LONG位置发送到此模拟器?我在模拟器上看到的唯一选项是将位置发送为GPS数据点。
背景
将于2016年10月15日对API 21进行一些平台更改,由于这些更改,我想测试我的应用程序的用户体验。这包括在仿真设备上进行测试
根据https://developer.android.com/guide/topics/location/strategies.html#Permission的说明,我们现在需要将以下uses-feature之一包含在清单中
android.hardware.location.network或android.hardware.location.gps
我的应用程序需要两者之一,因此我包括以下内容
<uses-feature
android:name="android.hardware.location" />
<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
<uses-feature
android:name="android.hardware.location.network"
android:required="false" />
Run Code Online (Sandbox Code Playgroud)
以下问题包含有关更改的一些信息:
什么时候需要android.hardware.location.gps和android.hardware.location.network?和