gpt4 book ai didi

android - 面临 map View 问题

转载 作者:行者123 更新时间:2023-11-29 18:17:28 27 4
gpt4 key购买 nike

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

here is the screen shot

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

`<?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>

在这种情况下,任何人都可以帮助我吗?

提前致谢

最佳答案

您有什么理由要使用 SDK 版本 3?我会推荐至少 7 或 8..

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

关于android - 面临 map View 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7319560/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com