1
我想在具有多個註釋的mapview上瀏覽我的城市,但我無法做到這一點。有誰建議我,我們如何在android中使用用戶定義的經度和緯度來做到這一點。我使用一個註釋創建了一個地圖視圖,但系統已定義,我必須從模擬器控制傳遞經度和緯度。我們如何使用具有多個註釋的代碼發送該代碼。在mapview中給出用戶定義的註釋
這裏是我的代碼:
package com.ex.maps;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Toast;
import android.widget.ZoomControls;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
public class HelloGoogleMaps extends MapActivity implements LocationListener{
MapController mc;
GeoPoint p;
double lat;
double lng;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView gMapView = (MapView) findViewById(R.id.mapview);
gMapView.setBuiltInZoomControls(true);
GeoPoint p = new GeoPoint((int) (lat * 1000000), (int) (lng * 1000000));
gMapView.setSatellite(true);
mc = gMapView.getController();
mc.setCenter(p);
mc.setZoom(14);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new HelloGoogleMaps();
//lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,mlocListener);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, this);
ZoomControls zoomControls = (ZoomControls) gMapView.getZoomControls();
zoomControls.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
gMapView.addView(zoomControls);
gMapView.displayZoomControls(true);
MyLocationOverlay myLocationOverlay = new MyLocationOverlay();
List<Overlay> list = gMapView.getOverlays();
list.add(myLocationOverlay);
/*List<Overlay> mapOverlays = gMapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.arrow_icon);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);
//GeoPoint p = new GeoPoint((int) (lat * 1000000), (int) (lng * 1000000));
OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);*/
}
public void onLocationChanged(Location location) {
if (location != null) {
lat = location.getLatitude();
lng = location.getLongitude();
p = new GeoPoint((int) (lat * 1000000), (int) (lng * 1000000));
mc.animateTo(p);
//Log.d("LOCATION CHANGED", location.getLatitude() + "");
//Log.d("LOCATION CHANGED", location.getLongitude() + "");*/
Toast.makeText(HelloGoogleMaps.this,
location.getLatitude() + "" + location.getLongitude(),
Toast.LENGTH_LONG).show();
}
}
//makeUseOfNewLocation(location);
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
protected boolean isRouteDisplayed() {
return true;
}
class MyLocationOverlay extends com.google.android.maps.Overlay {
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
super.draw(canvas, mapView, shadow);
Paint paint = new Paint();
// Converts lat/lng-Point to OUR coordinates on the screen.
Point myScreenCoords = new Point();
mapView.getProjection().toPixels(p, myScreenCoords);
paint.setStrokeWidth(1);
paint.setARGB(255, 255, 255, 255);
paint.setStyle(Paint.Style.STROKE);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);
canvas.drawText("Here I am...", myScreenCoords.x, myScreenCoords.y, paint);
return true;
} }
}