面对地图视图的问题

时间:2011-09-06 12:00:13

标签: android android-mapview

在这个项目中我遇到了一些运行时错误,我厌倦了通过粘贴谷歌中的错误来解决它并得到相应的结果。但我无法解决这个问题和

here is the screen shot

和其他代码很好但是清单文件显示了一些警告。代码是

`<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.collabera.labs.sai.maps"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <uses-library android:name="com.google.android.maps" />

        <activity android:name=".SampleMapActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="3" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

</manifest> `

它在第一行显示一些警告,即“属性minSdkVersion(3)低于项目目标API级别(8)”

这是我的java类

    package com.collabera.labs.sai.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.KeyEvent;
import android.widget.TextView;

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 MyMapActivity extends MapActivity implements LocationListener {
    /** Called when the activity is first created. */

    TextView        myLoc           = null;

    MapView         myMapView       = null;

    MapController   myMC            = null;

    GeoPoint        geoPoint        = null;

    double          latitude        = 12.937875, longitude = 77.622313;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Creating TextBox displaying Latitude, Longitude
        myLoc = (TextView) findViewById(R.id.id1);
        String currentLocation = "My location is: Lat: " + latitude + " Lng: " + longitude;
        myLoc.setText(currentLocation);

        // Creating and initializing Map
        myMapView = (MapView) findViewById(R.id.myGMap);
        geoPoint = new GeoPoint((int) (latitude * 1000000), (int) (longitude * 1000000));
        myMapView.setSatellite(false);

        //Getting the MapController to fine tune settings
        myMC = myMapView.getController();
        myMC.setCenter(geoPoint);
        myMC.setZoom(15);

        // Add a location mark
        MyLocationOverlay myLocationOverlay = new MyLocationOverlay();
        List<Overlay> list = myMapView.getOverlays();
        list.add(myLocationOverlay);

        // Adding zoom controls to Map
        myMapView.setBuiltInZoomControls(true);
        myMapView.displayZoomControls(true);

        // Getting locationManager and reflecting changes over map if distance travel by
        // user is greater than 500m from current location.
        LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, this);
    }


    public void onLocationChanged(Location location) {
        if (location != null) {
            Log.v("loc...", "location chaaaaaaaaa");
            double lat = location.getLatitude();
            double lng = location.getLongitude();
            String currentLocation = "The location is changed to Lat: " + lat + " Lng: " + lng;
            myLoc.setText(currentLocation);
            geoPoint = new GeoPoint((int) lat * 1000000, (int) lng * 1000000);
            myMC.animateTo(geoPoint);
        }
    }

    public void onProviderDisabled(String provider) {
        // required for interface, not used
    }

    public void onProviderEnabled(String provider) {
        // required for interface, not used
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
        // required for interface, not used
    }

    protected boolean isRouteDisplayed() {
        return false;
    }


    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_I) {
            myMapView.getController().setZoom(myMapView.getZoomLevel() + 1);
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_O) {
            myMapView.getController().setZoom(myMapView.getZoomLevel() - 1);
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_S) {
            myMapView.setSatellite(true);
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_M) {
            myMapView.setSatellite(false);
            return true;
        }
        return false;
    }

    /* Class overload draw method which actually plot a marker,text etc. on Map */
    protected class MyLocationOverlay extends com.google.android.maps.Overlay {

        @Override
        public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
            Paint paint = new Paint();

            super.draw(canvas, mapView, shadow);
            // Converts lat/lng-Point to OUR coordinates on the screen.
            Point myScreenCoords = new Point();
            mapView.getProjection().toPixels(geoPoint, myScreenCoords);

            paint.setStrokeWidth(1);
            paint.setARGB(255, 255, 255, 255);
            paint.setStyle(Paint.Style.STROKE);

            Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.marker);

            canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);
            canvas.drawText("I am here...", myScreenCoords.x, myScreenCoords.y, paint);
            return true;
        }
    }
}

我的xml文件是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:id="@+id/id1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >
</TextView>
<TextView
    android:id="@+id/id2"
    android:text="@string/index"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
<com.google.android.maps.MapView
    android:id="@+id/myGMap"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="0YaGLMeMFKXrhzHL-uSYZSnqXqbGwE6kxF4VwFQ"
    />


</LinearLayout>
在这种情况下,任何人都可以帮助我。

提前致谢

3 个答案:

答案 0 :(得分:1)

使用谷歌API 1.6或更多然后开发地图应用程序而不是android API。

 <uses-sdk android:minSdkVersion="7" /> or  <uses-sdk android:minSdkVersion="8" />

答案 1 :(得分:1)

您是否有任何理由要使用SDK版本3?我建议至少7或8 ..

         <uses-sdk 
          android:minSdkVersion="7" 
          android:targetSdkVersion="7"
         />

答案 2 :(得分:1)

创建一个Emulitor并将Target设置为Google而不是Android。 :)