綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] Android GPS 問題

[複製連結] 查看: 1660|回覆: 6|好評: 1
跳轉到指定樓層
樓主
951090121 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2013-9-12 22:03

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x

目前在寫一個抓GPS定位資訊的APP

因為小弟剛接觸照者書上的範例一步一步做

但時跑模擬器的時候卻出現

Unfortunately,GPS has stopped

的訊息

執行中沒有出現錯誤 SAVE 時沒 ERROR & WARNING

使得無從找起是哪裡有錯  

問題可能有點淺 小弟第一次寫APP

又是看書自學 無人可問 請多多包涵

以下是程式碼

MainActivity.java

package com.example.gps;

import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity implements LocationListener {
        private LocationManager mLocationManager;
        private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1;
        private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000;

       
       
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, this);


    }
    @Override   
    protected void onResume() {        
            if (mLocationManager != null) {            
                    mLocationManager.requestLocationUpdates(               
                                    LocationManager.GPS_PROVIDER,
                                    //LocationManager.NETWORK_PROVIDER,               
                                    0,               
                                    0,               
                                    this);        
                    }               
            super.onResume();   
            }
    @Override   
    protected void onPause() {        
            if (mLocationManager != null) {            
                    mLocationManager.removeUpdates(this);        
                    }               
            super.onPause();   
            }  
    public void onLocationChanged(Location location) {   
            TextView mTextView01 =(TextView) findViewById(R.id.textView1);
            TextView mTextView02 =(TextView) findViewById(R.id.textView2);
            TextView mTextView03 =(TextView) findViewById(R.id.textView3);
            TextView mTextView04 =(TextView) findViewById(R.id.textView4);
            TextView mTextView05 =(TextView) findViewById(R.id.textView5);
            TextView mTextView06 =(TextView) findViewById(R.id.textView6);
            TextView mTextView07 =(TextView) findViewById(R.id.textView7);
           
            mTextView01.setText(\"緯度-Latitude:  \" + String.valueOf(location.getLatitude()));
            mTextView02.setText(\"經度-Longitude:  \" + String.valueOf(location.getLongitude()));
            mTextView03.setText(\"精度-Accuracy:  \" + String.valueOf(location.getAccuracy()));
            mTextView04.setText(\"標高-Latitude:  \" + String.valueOf(location.getAltitude()));
            mTextView05.setText(\"時間-Time:  \" + String.valueOf(location.getTime()));
            mTextView06.setText(\"速度-Speed:  \" + String.valueOf(location.getSpeed()));
            mTextView07.setText(\"方位-Bearing:  \" + String.valueOf(location.getBearing()));   
            }
    public void onProviderDisabled(String provider) {   
           
    }     
    public void onProviderEnabled(String provider) {   
           
    }  
    public void onStatusChanged(String provider, int status, Bundle extras) {        
            switch (status) {        
            case LocationProvider.AVAILABLE:            
                    Log.v(\"Status\", \"AVAILABLE\");            
                    break;        
                    case LocationProvider.OUT_OF_SERVICE:            
                            Log.v(\"Status\", \"OUT_OF_SERVICE\");            
                            break;        
                    case LocationProvider.TEMPORARILY_UNAVAILABLE:            
                            Log.v(\"Status\", \"TEMPORARILY_UNAVAILABLE\");            
                            break;        
                            }   
                    }
}


AndroidManifest.xml

加入

    <uses-permission android:name=\"android.permission.INTERNET\"/>
    <uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>
    <uses-permission android:name=\"android.permission.ACCESS_MOCK_LOCATION\"/>
    <uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>



參考網頁
http://coosos.blogspot.tw/2012/07/gpsgoogle-map-android-library.html
http://www.moke.tw/wordpress/computer/advanced/279
「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏1 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
ploglin | 收聽TA | 只看該作者
發表於 2013-9-13 09:00
你是用模擬器嗎?還是實機?
看起來應該是捉不到 GPS 的內容
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

板凳
 樓主| 951090121 | 收聽TA | 只看該作者
發表於 2013-9-13 10:25
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

地板
ploglin | 收聽TA | 只看該作者
發表於 2013-9-13 10:59
安裝失敗應該是有其它的問題存在。
如果用模擬器的話,它有一個部份是 send gps 信號的功能,你可以試看看,或查一下資料
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

5
 樓主| 951090121 | 收聽TA | 只看該作者
發表於 2013-9-13 11:18
ploglin 發表於 2013-9-13 10:59
安裝失敗應該是有其它的問題存在。
如果用模擬器的話,它有一個部份是 send gps 信號的功能,你可以試看看 ...

想請問一下 還有甚麼方法可以找問題呢???
因為我的eclipse 並沒有 錯誤訊息
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

6
ploglin | 收聽TA | 只看該作者
發表於 2013-9-14 11:26
找不太到相關的資訊,你試著看能不能找到更多的錯誤資訊。
如果實機會當的話,LogCat應該會有exception的訊息,也可以放上來讓大家看一下
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

7
 樓主| 951090121 | 收聽TA | 只看該作者
發表於 2013-9-16 22:15
我找到問題了!!
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, this );



mLocationManager.requestLocationUpdates(               
                                     LocationManager.GPS_PROVIDER,                                         
                                     0,               
                                     0,               
                                     this);        

應該要一樣才行 !!

用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則