[問題] GPS程式問題

看板Eclipse作者 (Alfred)時間14年前 (2010/08/18 19:09), 編輯推噓3(305)
留言8則, 6人參與, 最新討論串1/1
今天有打一個用基地台定位的手機程式 目前只有在模擬器上跑過 可是 只要跑到append那裡似乎就會出錯 出錯的意思就是跑出"sorry"的那個視窗 把那部份註解掉程式可跑 以下是完整程式碼 .java //*************************************// package com.demo.android.mylocation; import android.app.Activity; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.widget.Toast; import android.location.Criteria; import android.util.Log; public class MyLocation extends Activity implements LocationListener{ /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); updateStat(); } private LocationManager mgr; private String best; private void updateStat() { // TODO Auto-generated method stub mgr = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); best = mgr.getBestProvider(criteria, true); Location location = mgr.getLastKnownLocation(best); StringBuffer msg = new StringBuffer(); msg.append("Latitude: "); //有問題部份 //msg.append(Double.toString(location.getLatitude())); //** msg.append(", Longitude: "); //有問題部份 //msg.append(Double.toString(location.getLongitude())); //** Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); } @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub Toast.makeText(this, location.toString(), Toast.LENGTH_LONG).show(); } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } protected void onResume() { super.onResume(); mgr.requestLocationUpdates(best, 60000, 1, this); } @Override protected void onPause(){ super.onPause(); mgr.removeUpdates(this); } } 還有一個部份 (有改動的)Manifest //*************************************// 主要改動部份:(都是新增) android.permission.ACCESS_COARSE_LOCATION android.permission.ACCESS_FINE_LOCATION android.permission.INTERNET //*************************************// <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.demo.android.mylocation" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MyLocation" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="3" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.INTERNET"></uses-permission> </manifest> 其他部分是沒有改動的 一行一行試的結果確定是append那裡出問題 append()直接給予字串不會有錯 可是在裡面引用其他函數或別的東西 就會出現問題 而去論壇有找過 好向也沒有相關文章 都是找到中文出勘誤的= = 有哪位神手大大可以給建議嗎? 感激不盡 PS:版面有點亂<(_ _)> 剛剛又試了一下發現.getLatitude()這類的函數一用就會出錯 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.64.183.231

08/18 19:16, , 1F
再補充一件事:這程式本人是完全依照
08/18 19:16, 1F

08/18 19:17, , 2F
"手機應用程式設計入門"第二版的第39章打的
08/18 19:17, 2F
※ 編輯: skywillnosky 來自: 203.64.183.231 (08/18 19:33)

08/18 19:52, , 3F
java程式問題建議可至java版詢問(而且那邊人比較多)
08/18 19:52, 3F

08/18 20:00, , 4F
android 版也可問android開發事項
08/18 20:00, 4F

08/18 21:26, , 5F
android版似乎仍以使用者導向為主,好像不太有開發相關
08/18 21:26, 5F

08/22 22:26, , 6F
location.getLatitude() 確定有拿到正確的東西??
08/22 22:26, 6F

08/25 16:16, , 7F
沒有也可以去問
08/25 16:16, 7F

10/28 00:35, , 8F
基地台是GSM定位 GPS是衛星導航 算是不太一樣的技術
10/28 00:35, 8F
文章代碼(AID): #1CQxzq91 (Eclipse)