Google Map
を上半分にAndroid Screen
表示し、Android画面の下半分にTextViewを表示するAndroidアプリケーションを作成しました。
そして、私は現在の場所Google Maps(on the Top half of the android screen)
に描画しており、からCircle
パスしています。そして、それはエミュレーターでうまく機能しています。current location (lat and long values)
DDMS perspective in the emulator
エミュレーターでアプリケーションを起動すると、まずAndroid画面の上半分にGoogleマップが表示され、下半分にTextViewが表示されます。次に、DDMSパースペクティブを使用して、現在の場所(緯度と経度の値)を渡します。通過した後、Googleマップの現在の場所に円を描画します。
そして、エミュレーターではすべてが正常に機能します。
問題文:-
しかし、実際に同じことを試していると、Android画面の上半分にAndroid Phone
自分だけGoogle Maps
が正しく表示され、Android画面の下半分にTextViewが表示されます。しかし、それは描画していませんCircle on my Current Location
。
AndroidフォンでWi-Fiに接続しています。そして、私はそうは思わないので、Androidフォンで緯度と経度の値を渡す必要がありますよね?現在の場所を自動的に取得する必要がありますか?
または、Androidフォンで行う必要があることはありますか?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new GPSLocationListener();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
locationListener);
mapView = (MapView) findViewById(R.id.mapView);
listView = (ListView) findViewById(R.id.mylist);
mapView.setStreetView(true);
mapView.setBuiltInZoomControls(true);
mapController = mapView.getController();
mapController.setZoom(15);
}
private class GPSLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
if (location != null) {
GeoPoint point = new GeoPoint(
(int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
findUsersInCurrentRadius(4,location.getLatitude(),location.getLongitude());
mapController.animateTo(point);
mapController.setZoom(15);
// add marker
MapOverlay mapOverlay = new MapOverlay(this,android.R.drawable.star_on,R.drawable.tenm,R.drawable.twentym,R.drawable.thirtym,R.drawable.fourtym);
mapOverlay.setPointToDraw(point);
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
String address = ConvertPointToLocation(point);
Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();
mapView.invalidate();
}
}
class MapOverlay extends Overlay {
private GeoPoint pointToDraw;
int[] imageNames=new int[6];
public MapOverlay(GPSLocationListener gpsLocationListener,
int currentUser, int tenm, int twentym, int thirtym, int fourtym) {
imageNames[0]=currentUser;
imageNames[1]=tenm;
imageNames[2]=twentym;
imageNames[3]=thirtym;
imageNames[4]=fourtym;
}
public void setPointToDraw(GeoPoint point) {
pointToDraw = point;
}
public GeoPoint getPointToDraw() {
return pointToDraw;
}
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(pointToDraw, screenPts);
//--------------draw circle----------------------
Point pt = mapView.getProjection().toPixels(pointToDraw,screenPts);
Paint circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
circlePaint.setColor(0x30000000);
circlePaint.setStyle(Style.FILL_AND_STROKE);
int totalCircle=4;
int radius=40;
int centerimagesize=35;
for (int i = 1; i <= totalCircle; i ++) {
canvas.drawCircle(screenPts.x,screenPts.y, i*radius, circlePaint);
}
canvas.drawBitmap(BitmapFactory.decodeResource(getResources(),imageNames[0]), (screenPts.x-(centerimagesize/2)),(screenPts.y-(centerimagesize/2)), null);
super.draw(canvas,mapView,shadow);
return true;
}
}
そして私のAndroidManifest.xmlファイル-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.circlemapandroid"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="8" />
<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" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:debuggable="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".ThesisProjectAndroid"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>