getCurrentLocationInBackground Parse.com [英] getCurrentLocationInBackground Parse.com

查看:394
本文介绍了getCurrentLocationInBackground Parse.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发应用程序,使用GPS位置的服务。应该每个服务都有一个位置(GeoPoint对象)。我试图让我的当前位置,并将其保存到数据库的解析。我试图用getCurrentLocationInBackground但遗憾的是没有关于如何使用本指南。我用下面的code可惜it't不工作。请帮助!

 无效的getLocation(){
        // ParseGeoPoint位置= NULL;
        标准标准=新标准();
        criteria.setAccuracy(Criteria.ACCURACY_LOW);
        criteria.setAltitudeRequired(假);
        criteria.setBearingRequired(假);
        criteria.setCostAllowed(真);
        criteria.setPowerRequirement(Criteria.POWER_LOW);        ParseGeoPoint.getCurrentLocationInBackground(20000,标准,新LocationCallback(){
          @覆盖
          公共无效完成(ParseGeoPoint的GeoPoint,ParseException的E){            如果(E == NULL){                Toast.makeText(getApplicationContext(),geoPoint.getLatitude()+,50000).show();
            }其他{
              //处理您的错误
              e.printStackTrace();
              Toast.makeText(getApplicationContext(),错误,50000).show();
            }
          }
        });
}


解决方案

我能够在build.grade添加以下的依赖来解决这个问题:

  {相关性
    编译com.google.android.gms:播放服务地点:7.5.0
}

我也不得不删除所有 ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION 从AndroidManifest.xml中的权限,这似乎很奇怪。

您已经定义了标准的方式是正确的,也是必要的。

这是Parse.com API中一个非常不错的功能,但我希望他们能提供一些文件。由于是,我真的不相信它......我只是用它作为一个快速和肮脏的解决方案,直到我有时间去实现谷歌正常播放服务。

I'm trying to develop application that uses GPS locations for services. Each service should has a location (GeoPoint). I'm trying to get my current location and save it to parse database. I tried to use getCurrentLocationInBackground but unfortunately there is not guide on how to use this. I used the below code but unfortunately it't not working. Please help!

void getLocation() {


        // ParseGeoPoint location = null;
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_LOW);
        criteria.setAltitudeRequired(false);
        criteria.setBearingRequired(false);
        criteria.setCostAllowed(true);
        criteria.setPowerRequirement(Criteria.POWER_LOW);

        ParseGeoPoint.getCurrentLocationInBackground(20000, criteria, new LocationCallback() {
          @Override
          public void done(ParseGeoPoint geoPoint, ParseException e) {

            if (e == null) {

                Toast.makeText(getApplicationContext(), geoPoint.getLatitude()+"", 50000).show();


            } else {
              // handle your error
              e.printStackTrace();
              Toast.makeText(getApplicationContext(),"error", 50000).show();
            }
          }
        });


}

解决方案

I was able to fix this by adding the following dependency in build.grade:

dependencies {
    compile 'com.google.android.gms:play-services-location:7.5.0'
}

I also had to remove all ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permissions from AndroidManifest.xml, which seems very strange.

The way you have defined the Criteria is correct, and also necessary.

This is a really nice feature in the Parse.com API but I wish they would provide some documentation. As is, I don't really trust it... I'm just using it as a quick and dirty solution until I have time to implement Google Play Services properly.

这篇关于getCurrentLocationInBackground Parse.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆