gpt4 book ai didi

android - 空载Map Android-Google Maps V2

转载 作者:行者123 更新时间:2023-12-02 11:12:46 24 4
gpt4 key购买 nike

我在创建Google Maps V2 Android应用程序时遇到问题。对不起,我的英语。这是我的问题:

01-17 15:24:55.844: E/AndroidRuntime(26859): Caused by: java.lang.IllegalStateException: 
The meta-data tag in your app's AndroidManifest.xml does not have the right value.
Expected 6171000 but found 0. You must have the following declaration within the <application> element:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

MainActivity:
import android.app.Dialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends FragmentActivity {

GoogleMap googleMap;
SharedPreferences sharedPreferences;
int locationCount = 0;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


// Getting Google Play availability status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

// Showing status
if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available

int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();

}else { // Google Play Services are available

// Getting reference to the SupportMapFragment of activity_main.xml
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

// Getting GoogleMap object from the fragment
googleMap = fm.getMap();

// Enabling MyLocation Layer of Google Map
googleMap.setMyLocationEnabled(true);

// Opening the sharedPreferences object
sharedPreferences = getSharedPreferences("location", 0);

// Getting number of locations already stored
locationCount = sharedPreferences.getInt("locationCount", 0);


// Getting stored zoom level if exists else return 0
String zoom = sharedPreferences.getString("zoom", "0");

// If locations are already saved
if(locationCount!=0){

String lat = "";
String lng = "";

// Iterating through all the locations stored
for(int i=0;i<locationCount;i++){

// Getting the latitude of the i-th location
lat = sharedPreferences.getString("lat"+i,"0");

// Getting the longitude of the i-th location
lng = sharedPreferences.getString("lng"+i,"0");

// Drawing marker on the map
drawMarker(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng)));
}

// Moving CameraPosition to last clicked position
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(Double.parseDouble(lat), Double.parseDouble(lng))));

// Setting the zoom level in the map on last position is clicked
googleMap.animateCamera(CameraUpdateFactory.zoomTo(Float.parseFloat(zoom)));
}

}

googleMap.setOnMapClickListener(new OnMapClickListener() {

@Override
public void onMapClick(LatLng point) {
locationCount++;

// Drawing marker on the map
drawMarker(point);

/** Opening the editor object to write data to sharedPreferences */
SharedPreferences.Editor editor = sharedPreferences.edit();

// Storing the latitude for the i-th location
editor.putString("lat"+ Integer.toString((locationCount-1)), Double.toString(point.latitude));

// Storing the longitude for the i-th location
editor.putString("lng"+ Integer.toString((locationCount-1)), Double.toString(point.longitude));

// Storing the count of locations or marker count
editor.putInt("locationCount", locationCount);

/** Storing the zoom level to the shared preferences */
editor.putString("zoom", Float.toString(googleMap.getCameraPosition().zoom));

/** Saving the values stored in the shared preferences */
editor.commit();

Toast.makeText(getBaseContext(), "Marker is added to the Map", Toast.LENGTH_SHORT).show();

}
});


googleMap.setOnMapLongClickListener(new OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng point) {

// Removing the marker and circle from the Google Map
googleMap.clear();

// Opening the editor object to delete data from sharedPreferences
SharedPreferences.Editor editor = sharedPreferences.edit();

// Clearing the editor
editor.clear();

// Committing the changes
editor.commit();

// Setting locationCount to zero
locationCount=0;

}
});


}

private void drawMarker(LatLng point){
// Creating an instance of MarkerOptions
MarkerOptions markerOptions = new MarkerOptions();

// Setting latitude and longitude for the marker
markerOptions.position(point);

// Adding marker on the Google Map
googleMap.addMarker(markerOptions);
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.wptrafficanalyzer.locationmarkerpreferences"
android:versionCode="1"
android:versionName="1.0" >

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

<permission
android:name="in.wptrafficanalyzer.locationmarkerpreferences.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>

<uses-permission android:name="in.wptrafficanalyzer.locationmarkerpreferences.permission.MAPS_RECEIVE"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="in.wptrafficanalyzer.locationmarkerpreferences.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBDEKZK3rQiiqC6q1ZXCuDvL5iC00-EOnY" />

</application>

</manifest>

activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />


</RelativeLayout>

属性:

最佳答案

您应该已经阅读了粘贴在此处的异常,并按照其说明执行了以下操作:

Caused by: java.lang.IllegalStateException: 
The meta-data tag in your app's AndroidManifest.xml does not have the right value.
Expected 6171000 but found 0. You must have the following declaration within the <application> element:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

因此只需编辑 list 并添加
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

对此。

关于android - 空载Map Android-Google Maps V2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28002469/

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