Android GPS
10036 ワード
AdnroidプラットフォームのGPSデバイスを実用化するには、まず権限を追加する必要があります。
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
<
uses
-
permission android:name
=
"
android.permission.ACCESS_FINE_LOCATION
"
></
uses
-
permission
GPS :
private
void
openGPSSettings() {
LocationManager alm
=
(LocationManager)
this
.getSystemService(Context.LOCATION_SERVICE);
if
(alm
.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
Toast.makeText(
this
,
"
GPS
"
, Toast.LENGTH_SHORT)
.show();
return
;
}
Toast.makeText(
this
,
"
GPS!
"
, Toast.LENGTH_SHORT).show();
Intent intent
=
new
Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivityForResult(intent,
0
);
//
}
, , , GPS :
:
private
void
getLocation()
{
//
LocationManager locationManager;
String serviceName
=
Context.LOCATION_SERVICE;
locationManager
=
(LocationManager)
this
.getSystemService(serviceName);
//
Criteria criteria
=
new
Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
//
criteria.setAltitudeRequired(
false
);
criteria.setBearingRequired(
false
);
criteria.setCostAllowed(
true
);
criteria.setPowerRequirement(Criteria.POWER_LOW);
//
String provider
=
locationManager.getBestProvider(criteria,
true
);
//
GPS
Location location
=
locationManager.getLastKnownLocation(provider);
//
GPS
updateToNewLocation(location);
//
, N (1 1*1000, ) N
locationManager.requestLocationUpdates(provider,
100
*
1000
,
500
,
locationListener);
}
ここで を できますが、 したい は の で します。
prvate
void
udateToNewLocation{Location location}Text View tv 1;tv 1
を します。
(TextView)
this
findView ById(R.id.tv 1)
if
(location)
!=
null
){
ドビー
latitude
を します。
location.get Latitude()
ドビー
longitude
を します。
location.get Longitude();tv 1.set Text(
「
:
「
+
latitude
+
「
/n
「
+
longitude);
else
{tv 1.set Text(
「
を できませんでした。
「
);
このようにして、 の の が られます。 なくともどのようにして で されますか? で し、 されます。
AndroidクライアントでGoogle を するには、googleのAPIを います。 ったのはAndroidのSDKではなく、 Googleのものです。 しく べていないので、 にどのぐらいの いがありますか?まだよく かりません。 があるなら、もう しよく てください。 を するのはViewです。comp.google.android.maps.MapViewですが、 うなら、googleにMapのKeyを してください。 にはどのように すればいいですか?
で げたら、 はネットを っていますので、ネットへのアクセス が です。これを する があります。 が できません。
は コードです。
まず のコントローラを します。
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
private
MapController mapController;
private
GeoPoint geoPoint; //
そして えられます!
は コードです。
set ContentView(R.layout.main)MapView mapView
を します。
(MapView)findView ById(R.id.mapview 1)mapController
を します。
mapView.get Controller()mapView.set Enbaled(
true
)0mapView.set Clicable(
true
)0mapView.set Buiilt InZoomControls(
true
)0geoPoint
を します。
new
GeoPoint((
)
40.976,66666667
*
1000 です
を します。
)
116.8166666667
*
1000 です
)0map Controller.animation To(geoPoint)mapController.setZoom(
12
)0
ある に を するには、 の で できます。
クラス
MyLocationOverlay
extens
Overlay{@Override
public
bollan
draw(Canvas canvas、MapView mapView、
bollan
sharow
long
when){
スーパー
draw(canvas,mapView,show);Paint paint
を します。
new
Paint();Point mysScrenCoords
を します。
new
Point()
//
を のスクリーン に します。
mapView.get Projection().toPixels(geoPoint,myScrenCoords);paint.set Stroke Width(
1
);paint.setARGB(
255
を します。
255
を します。
0
を します。
0
);paint.set Style(Paint.Style.STROKE);Bitmap bmp
を します。
Bitmap Factory.decodeResource(gets Resource);canvas.drawable.home);canvas.drawBitmap(bmp,mysScrenCoords.x,mysScrenCoords.y,paint);canvas.drawText(
「
する
「
myScrenCoords.x,mysScrenCoords.y,paint);
return
true
}
もちろん を します。もし たちが き いでいるのがActivityであれば、 できないので、MapActivityに したいです。これはなぜgoogle Appを うのですか?
はい、この は に ったGPS と わせてもう しました。 にGPSによる が できます。 は らを び けて ができます。
:http://www.cnblogs.com/fly_binban/archive/2010/12/16/1908518.html