リハビリ
Google Map javascript API V3 云々。
過去ログ確認してみました。
- http://d.hatena.ne.jp/yamanetoshi/20100518/1274190057
- http://d.hatena.ne.jp/yamanetoshi/20100524/1274709872
- http://d.hatena.ne.jp/yamanetoshi/20100525/1274744816
- http://d.hatena.ne.jp/yamanetoshi/20100525/1274781578
実はいっちゃん最後の実装が職場端末に無かったんスよ。しかし、LocationManager 使ってる意味があまり無いので、ソレを使うナニを書いて実機で動かしてみます。
LocationManagerService 関連
onPause で云々しなければ、な記述があったような気がしたんですが、自分ログにはそれが残ってません。で、職場端末を漁ってみたら以下な実装を書いてました。
package com.example.gs; import java.io.IOException; import java.util.Date; import java.util.List; import java.util.Locale; import android.app.Activity; 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.location.LocationProvider; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import android.widget.Toast; public class GPSActivity extends Activity implements LocationListener { private final String app_tag = "GPSActivity"; private LocationManager locationManager; private Geocoder geoCoder; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE); geoCoder = new Geocoder(getApplicationContext(), Locale.JAPAN); setContentView(R.layout.main); } @Override public void onLocationChanged(Location location) { TextView textView = (TextView)findViewById(R.id.location_text); String str; Date d = new Date(location.getTime()); str = "Time:" + d.toString() + "\n"; str += "Latitude:" + String.valueOf(location.getLatitude()) + "\n"; str += "Longitude:" + String.valueOf(location.getLongitude()) + "\n"; str += "Accuracy:" + String.valueOf(location.getAccuracy()) + "\n"; str += "Altitude:" + String.valueOf(location.getAltitude()) + "\n"; str += "Bearing:" + String.valueOf(location.getBearing()) + "\n"; str += "Speed:" + String.valueOf(location.getSpeed()) + "\n"; textView.setText(str); showLocationName(location); } private void showLocationName(Location location) { double latitude = location.getLatitude(); double longitude = location.getLongitude(); StringBuffer buf = new StringBuffer(); try { List<Address> addrs = geoCoder.getFromLocation(latitude, longitude, 1); for(Address addr : addrs) { int index = addr.getMaxAddressLineIndex(); for (int i = 0; i <= index; i++) { buf.append(addr.getAddressLine(i)); buf.append(" "); } buf.append("\n"); } } catch (IOException e) { Log.e(app_tag, e.toString()); } } @Override protected void onPause() { if (locationManager != null) locationManager.removeUpdates(this); super.onPause(); } @Override protected void onResume() { super.onResume(); if (locationManager != null) { Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) onLocationChanged(location); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, this); } } @Override public void onProviderDisabled(String provider) { TextView textView = (TextView)findViewById(R.id.provider_text); Toast.makeText(this, "onProviderDisabled", Toast.LENGTH_SHORT).show(); textView.setText("provider:" + provider); } @Override public void onProviderEnabled(String provider) { TextView textView = (TextView)findViewById(R.id.provider_text); Toast.makeText(this, "onProviderEnabled", Toast.LENGTH_SHORT).show(); textView.setText("provider:" + provider); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub TextView statusText = (TextView)findViewById(R.id.status_text); TextView providerText = (TextView)findViewById(R.id.provider_text); providerText.setText("provider:" + provider); switch (status) { case LocationProvider.AVAILABLE: statusText.setText("status:AVAILABLE"); break; case LocationProvider.OUT_OF_SERVICE: statusText.setText("status:OUT_OF_SERVICE"); break; case LocationProvider.TEMPORARILY_UNAVAILABLE: statusText.setText("status:TEMPORARILY_UNAVAILABLE"); break; } } }
onPause および onResume で必要な処理がある、という記憶があります。上記は LocationListener をきちんと使ってる例、と言って良いはずなんですが。
閑話休題
検索してみたらまとめなエントリが無いみたいなんで、週末のもくもくなソレを使って情報を取り纏める必要があるな、と思ってます。
週末は wpa_supplicant なナニを、と思っているのですがどうなるやら。
他にもヤらねば、なソレがあるんですが、とりあえず休みます。
# しかも標題と中身が全然違うぞ (とほほ