我有服务.并且有一个名为onServiceUpdate()的方法.此方法类似于Google Maps API中的onLocationChanged().
所以我想在onServiceUpdate()方法中启动CountDownTimer,但显示如下错误:
Can't create handler inside thread that has not called Looper.prepare()
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:200)
at android.os.Handler.<init>(Handler.java:114)
at android.os.CountDownTimer$1.<init>(CountDownTimer.java:114)
at android.os.CountDownTimer.<init>(CountDownTimer.java:114)
at skripsi.ubm.studenttracking.Service2$6.<init>(Service2.java:317)
at skripsi.ubm.studenttracking.Service2.onServiceUpdate(Service2.java:317)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
@Override
public void onServiceUpdate(ServiceState state)
{
final float[] distance = new float[2];
Location.distanceBetween(state.getGeoPoint().getLatitude(), state.getGeoPoint().getLongitude(), 6.130607787619352,106.81839518499267, distance);
if (distance[0] > 25.0)
{
CountDownTimer cdt5 = new CountDownTimer(total_onServiceUpdate,1000) {
@Override
public void onTick(long millisUntilFinished) {
total_onServiceUpdate = millisUntilFinished/1000;
}
@Override
public void onFinish() { …Run Code Online (Sandbox Code Playgroud) 当我的蓝点图标消失时,我感到困惑.过去是我可以展示蓝点图标.但现在只需将相机放在当前位置,而不用蓝点图标.
这是我的代码:
private void handleNewLocation(Location location) {
Log.d(TAG, location.toString());
double currentLatitude = location.getLatitude();
double currentLongitude = location.getLongitude();
LatLng latLng = new LatLng(currentLatitude, currentLongitude);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 21));
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Android Studio 1.1.0.当我尝试同步我的Gradle文件时,出现以下错误:
找不到Gradle DSL方法:storeFile()
这是我的gradle配置:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "skripsi.ubm.studenttracking"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
signingConfigs {
release {
storeFile (project.property("Students_tracking_keystore.jks") + ".keystore")
storePassword "####"
keyAlias "####"
keyPassword "#####"
}
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
我正在使用Google Maps API.
我想要的是当我移动到某个特定位置并且我已经在地图上绘制了一个圆圈时,它将转到另一个活动.
所以它就像:
我的位置是a =(X,Y)
圆位置是b =(X,Y)半径= 10
当我在半径范围内时,它将转到另一个活动或做某事.
有任何想法吗 ?
我已经在使用distanceTo(),但仍然没有成功.
编辑:这是更新的代码仍然不适合我:
public void onLocationChanged(Location location)
{
float [] distance = new float[];
Location.distanceBetween(location.getLatitude(),location.getLongitude(),-6.xxxxxxx,106.xxxxxxx,distance);
if (distance[0] < 50)
{
Intent i = new Intent(student_activity.this,indoor.class);
student_activity.this,startActivity(i);
}
}
Run Code Online (Sandbox Code Playgroud)
此方法setUpMapIfNeeded()在onCreate方法中调用:
public void circle()
{
Circle circle = mMap.addCircle (new CircleOptions()
.center(new LatLng(-6.xxxxxxx,106.xxxxxxx))
.radius(50)
.strokeColor(Color.RED)
.strokeWidth(1)
.fillColor(Color.RED)
}
Run Code Online (Sandbox Code Playgroud) 我有以下代码:
public SensorEventListener sensorEventListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
float pressure_value = 0.0f;
float height = 0.0f;
if (Sensor.TYPE_PRESSURE == event.sensor.getType())
{
pressure_value = event.values[0];
height = SensorManager.getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, pressure_value);
}
value = String.valueOf(height);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
Run Code Online (Sandbox Code Playgroud)
我在09.AM有高度计,例如43,xxxxxxx.
我在09.PM再次检查,结果正在发生变化.它改变2米或更多.
是因为月亮或其他任何东西改变了压力?
以及如何解决这个问题?
我已阅读以下主题:Android:如何获得准确的海拔高度?
但我仍然感到困惑.你能指导我如何编写代码吗?值得注意的是,我想基于气压传感器使用它.