0
在我的應用程序中,我想在單個地圖中顯示兩個經緯度。我得到一個值作爲當前經緯度,其他值作爲手動輸入。我用不同的標記標記這兩個點安卓地圖無法看到兩個點
但是我能夠在我的地圖中看到只有一個標記,也就是當前的位置。以下是我的代碼,
MapView mapView;
MapController mc,mc1;
GeoPoint p,q;
double latPoint,lngPoint;
double latPoint1 = 9.909186;
double lngPoint1 = 78.102936;
class MapOverlay extends com.google.android.maps.Overlay
{
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(p, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource
(
getResources(), R.drawable.pin);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
return true;
}
}
class SitesOverlay extends com.google.android.maps.Overlay
{
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(q, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource
(
getResources(), R.drawable.marker);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
return true;
}
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
mapView = (MapView) findViewById(R.id.mapView);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
android.view.View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
mc = mapView.getController();
mc1 = mapView.getController();
LocationManager myManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
if(myManager != null)
{
//List list = myManager.getAllProviders();
String param = (String)myManager.getProviders(true).get(0);
Location loc = myManager.getLastKnownLocation(param);
if(loc != null)
{
latPoint = loc.getLatitude();
lngPoint = loc.getLongitude();
}
else
Log.e("GoogleMaps ","Error: Location is null");
}
else
Log.e("GoogleMaps ","Error: Location Manager is null");
p = new GeoPoint
(
(int) (latPoint * 1E6),
(int) (lngPoint * 1E6)
);
mc.animateTo(p);
mc.setZoom(17);
mapView.invalidate();
//---Add a location marker---
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapView.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
q = new GeoPoint
(
(int) (latPoint1 * 1E6),
(int) (lngPoint1 * 1E6)
);
mc1.animateTo(q);
mc1.setZoom(17);
mapView.invalidate();
SitesOverlay sitesOverlay = new SitesOverlay();
List<Overlay> listOfOverlays1 = mapView.getOverlays();
listOfOverlays1.clear();
listOfOverlays1.add(mapOverlay);
mapView.invalidate();
請幫我的朋友......