为了账号安全,请及时绑定邮箱和手机立即绑定

在接收到经度和纬度时,如何停止GPS?

在接收到经度和纬度时,如何停止GPS?

叮当猫咪 2019-03-14 19:15:52
我做了一个 geolocation 程序,该程序能正常运行,但总是循环持续显示toast。代码如下:package com.application.geocoding; import java.io.IOException; import java.util.List; import java.util.Locale; import android.app.Activity; import android.os.Bundle; import android.content.Context; import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.widget.TextView; import android.widget.Toast; public class main extends Activity {     /** Called when the activity is first created. */     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);         geoLocation();     }     public void geoLocation()     {         LocationManager locationManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);         LocationListener locationListener = new LocationListener() {             public void onLocationChanged(Location location) {               // Called when a new location is found by the network location provider.               //makeUseOfNewLocation(location);                 updateWithNewLocation(location);             }             public void onStatusChanged(String provider, int status, Bundle extras) {}             public void onProviderEnabled(String provider) {                 Toast.makeText(main.this,"Network Enabled",Toast.LENGTH_SHORT ).show();             }             public void onProviderDisabled(String provider) {                 Toast.makeText(main.this,"Network Disabled",Toast.LENGTH_SHORT ).show();             }           };         // Register the listener with the Location Manager to receive location updates         locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);     }谁知道我应该把这一行放在哪儿?locationManager.removeUpdates(locationListener);那么它就会只运行一次?
查看完整描述

2 回答

?
慕哥9229398

TA贡献1877条经验 获得超6个赞

放在geoLocation()后面不就好了吗?


查看完整回答
反对 回复 2019-04-27
  • 2 回答
  • 0 关注
  • 484 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信