new locationclient(this,this,this) 编译错误

2024-01-10

我正在尝试使用新的谷歌位置服务更新旧教程。我直接使用谷歌教程中的代码,但行 mLocationClient = new LocationClient(this,this,this);返回错误 构造函数 LocationClient(RunFragment, RunFragment, RunFragment) 未定义

我的代码和教程之间的唯一区别是我在片段中的 onCreateView 中运行它,而不是从 Activity 中运行。有什么建议我可以纠正这个问题吗?谢谢。

public class RunFragment extends Fragment implements

位置监听器, GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener {

private Button mStartButton, mStopButton;
private TextView mStartedTextView, mLatitudeTextView, 
    mLongitudeTextView, mAltitudeTextView, mDurationTextView;


// A request to connect to Location Services
private LocationRequest mLocationRequest;

// Stores the current instantiation of the location client in this object
private LocationClient mLocationClient;

// Handle to SharedPreferences for this app
SharedPreferences mPrefs;

// Handle to a SharedPreferences editor
SharedPreferences.Editor mEditor;

/*
 * Note if updates have been turned on. Starts out as "false"; is set to "true" in the
 * method handleRequestSuccess of LocationUpdateReceiver.
 *
 */
boolean mUpdatesRequested = false;

@Override
public void onCreate(Bundle savedInstanceState) {


    super.onCreate(savedInstanceState);
    setRetainInstance(true);



}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_run, container, false);

    mStartedTextView = (TextView)view.findViewById(R.id.run_startedTextView);
    mLatitudeTextView = (TextView)view.findViewById(R.id.run_latitudeTextView);
    mLongitudeTextView = (TextView)view.findViewById(R.id.run_longitudeTextView);
    mAltitudeTextView = (TextView)view.findViewById(R.id.run_altitudeTextView);
    mDurationTextView = (TextView)view.findViewById(R.id.run_durationTextView);

    mStartButton = (Button)view.findViewById(R.id.run_startButton);


    mStopButton = (Button)view.findViewById(R.id.run_stopButton);

    // Create a new global location parameters object
    mLocationRequest = LocationRequest.create();

    /*
     * Set the update interval
     */
    mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);

    // Use high accuracy
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

    // Set the interval ceiling to one minute
    mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);

    // Note that location updates are off until the user turns them on
    mUpdatesRequested = false;

    // Open Shared Preferences

    mPrefs = getActivity().getSharedPreferences(LocationUtils.SHARED_PREFERENCES, Context.MODE_PRIVATE);

    // Get an editor
    mEditor = mPrefs.edit();

    /*
     * Create a new location client, using the enclosing class to
     * handle callbacks.
     */
    mLocationClient = new LocationClient(this,this,this);



    //updateUI();

    return view;
}

@Override
public void onConnectionFailed(ConnectionResult result) {
    // TODO Auto-generated method stub

}

@Override
public void onConnected(Bundle connectionHint) {
    // TODO Auto-generated method stub

}

@Override
public void onDisconnected() {
    // TODO Auto-generated method stub

}

@Override
public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub

}

}


第一个参数必须是活动的上下文。

在您的 MainActivity 中声明:

public static Context c;

在MainActivity的onCreate方法中:

c = this;

现在你可以像这样调用你的方法:

mLocationClient = new LocationClient(MainActivity.c, this, this); 

注意:MainActivity 是已膨胀您的片段的 Activity。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

new locationclient(this,this,this) 编译错误 的相关文章

随机推荐

  • 信号发射结构

    这个问题在我脑海里萦绕了很多天 但直到现在我才弄清楚 如果我尝试发送一个结构信号 struct radarStruct unsigned char Data unsigned int rate unsigned int timeStamp
  • ADB 设备卡在“连接”状态

    我正在尝试将我的手机连接到 Android Studio 以跟进一些应用程序开发 我目前正在努力将手机正确连接到计算机 因为 ADB 似乎从未连接到设备 当尝试在设备上启动应用程序时 这是 Android Studio 在运行控制台中告诉我
  • 如何向背景图像添加颜色叠加? [复制]

    这个问题在这里已经有答案了 我在 SO 和 Web 上都看到过很多这个问题 但它们都不是我要寻找的 如何仅使用 CSS 将颜色叠加添加到背景图像 HTML 示例 div class testclass div CSS 示例 testclas
  • R 和 ggplot-将 x 轴更改为日期可消除位置闪避

    我一直在使用 ggplot 来创建绘图 并且我总是喜欢水平偏移数据点 这样误差线就不会重叠 我发现当我使用日期数据作为 x 轴时 我失去了偏移数据点的能力 DF data frame Date c 2006 09 01 2007 09 01
  • 我怎样才能停止ajax请求(不要等到响应到来)?

    如果我使用Ajax发送请求并且这个请求需要很长时间 如果我想发送花药请求我该怎么办 当前的行为第二个请求 我做了 等待第一个请求得到响应 NOTE 我想在整个应用程序上执行此行为 任何新请求立即执行 而不是等待旧请求首先完成 我的应用程序使
  • 为什么我必须重新解释指针指针?

    So this static cast代码是完全合法的 int n 13 void pn static cast
  • MS Visual Studio 2012 可以与 Windows Vista 一起使用吗?

    我运行 Windows Vista Business 并想尝试 MS Visual Studio Express 2012 它们兼容吗 兼容性列表在哪里 至少官方没有 http www microsoft com visualstudio
  • 这个 GCD 实现的 getter setter 线程安全并且比 @synchronized 工作得更好吗?对象

    interface ViewController property nonatomic strong NSString someString end implementation ViewController synthesize some
  • wxPython ListCtrl 帮助

    我正在使用 ListCtrl 它会动态填充项目 当项目 激活 双击 Enter 时 它会调用一个函数 def onClick self event 由于没有预设 ID 我如何找出列表中的哪个项目被单击 字符串是作为自身还是事件的一部分传递给
  • Tensorflow、train_step 馈送不正确

    我正在从 Convnetjs 切换到 Tensorflow 并且正在学习读取图像和使用 Tensorflow 训练 CNN 的基础知识 我在两个文件夹中有一堆 160 120 1 的图像 train go 和 train no 所以我使用两
  • 当模板名称是变量时如何使用 Groovy 模板引擎?

    我正在尝试找到一种方法来使用常规变量而不是使用硬编码的模板名称 当前代码如下所示 SCRIPT template groovy html template 我尝试使用嵌套变量扩展 但仍然出现错误 Example def body SCRIP
  • Apple PrefPane 示例无法构建,并出现 clang 错误,同时反对 -fobjc-arc 和 -fobjc-gc

    我正在尝试构建一个首选项窗格作为学习 OS X 开发的一部分 下载苹果的后首选项窗格示例代码 https developer apple com library mac samplecode PrefsPane Introduction I
  • python 上的 Latex:\alpha 和 \beta 不起作用?

    我使用 matplotlib 生成一些图形 并使用乳胶作为图例 更具体地说 我正在尝试使用这样的东西 loglog x x r label alpha legend show 但是 此代码不会在图形上显示图例 并且在关闭图像后出现错误 我正
  • CHtmlview (MFC) 中的 svg

    我无法在 MFC 应用程序中从 CHtmlView 派生的视图中使用 SVG 进行绘制 但是 当我在记事本中复制相同的源并使用 Internet Explorer 打开它时 它正在工作 我的机器上安装的IE版本是IE9 有人可以帮我解决这个
  • 在python中,random.uniform()和random.random()有什么区别?

    在 python 中 random 模块有什么区别random uniform and random random 它们都生成伪随机数 random uniform 从均匀分布生成数字并random random 生成下一个随机数 有什么不
  • 如何在 Google Apps 脚本中缓存对象

    我正在 Google Drive 电子表格的脚本中从 JIRA 获取 JSON 数据 我有一个脚本可以很好地获取数据 而且我几乎只获取该问题的数据 我返回的是 JSON 文本字段 表示有关特定 JIRA 问题的所有数据 我不想每次需要特定
  • TFS 门控签入——如何拒绝部分构建成功签入?

    我有一个构建后脚本 powershell 它会按照预期抛出异常 构建后脚本在 构建后脚本路径 部分的构建定义中定义 该异常记录在构建的 其他错误和警告 部分中 打开门控签入后 即使构建被归类为 部分 因为构建后脚本失败 更改仍然会提交 似乎
  • 将 Google App Engine 数据存储导出到 MySQL?

    我们正在考虑在 Google App Engine 上构建一些基础设施 但我们担心如果它无法扩展 我们将来需要导出数据并在我们自己的服务器上运行 有没有办法从 App Engine 数据存储区导出到 MySQL 就数据导出而言 批量下载器
  • sfinae 位于类体外部定义的成员函数上

    有点像我的延续上一个问题 https stackoverflow com questions 11694970 c11 style sfinae and function visibility on template instantiati
  • new locationclient(this,this,this) 编译错误

    我正在尝试使用新的谷歌位置服务更新旧教程 我直接使用谷歌教程中的代码 但行 mLocationClient new LocationClient this this this 返回错误 构造函数 LocationClient RunFrag