【发布时间】:2014-11-12 13:20:28
【问题描述】:
你好, 我已经阅读了很多关于如何使地图与 11sdk 以外的情人一起工作的回复,但我做了所有事情,但我仍然无法让它工作。我的 minsdk 设置为 8。我总是收到这样的错误:
清单合并失败:uses-sdk:minSdkVersion 8 不能小于库 com.google.android.gms:play-services:6.1.71 中声明的版本 9`
我无法将我的 min sdk 更改为 9 或 11,因为我迫切需要它为 8。我已经尝试更改为 supportmapfragment 等等。这是我的代码: fragment_maps.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
maps.java
package com.miesto.meniu;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.*;
import android.os.Build;
import com.google.android.gms.maps.SupportMapFragment;
import android.widget.Toast;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import java.text.SimpleDateFormat;
public class maps extends FragmentActivity {
Fragment fragment = getSupportFragmentManager().findFragmentById(
R.id.mapView);
SupportMapFragment mapFragment = (SupportMapFragment) fragment;
GoogleMap mMap = mapFragment.getMap();
@Override
protected void onCreate(Bundle savedInstanceState) {
createMapView();
addMarker();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
GoogleMap googleMap;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.maps, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_maps, container, false);
return rootView;
}
}
/**
* THIS WONT WORK SO I JUST COMMENTED IT BUT LEFT IT IF ILL NEED IT LATER
*/
private void createMapView(){
/**
* Catch the null pointer exception that
* may be thrown when initialising the map
try {
if(null == googleMap){
HERE I GET ERROR THAT getfragmentmanager and findfragmentbyid NEED minsdk 11
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.mapView)).getMap();
if(null == googleMap) {
Toast.makeText(getApplicationContext(),
"Klaida rodant zemelapi", Toast.LENGTH_SHORT).show();
}
}
} catch (NullPointerException exception){
Log.e("miesto.meniu", exception.toString());
}
*/
}
/** -------------------------------
*
*/
/**
* Adds a marker to the map
*/
private void addMarker(){
/** Make sure that the map has been initialised **/
if(null != googleMap){
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Marker")
.draggable(true)
);
}
}
}
任何帮助将不胜感激
【问题讨论】:
-
“我无法将我的 min sdk 更改为 9 或 11,因为我迫切需要它为 8”——那么您应该进行研究以找到适用于 API 级别的地图解决方案8. 例如,您可以查看 OpenStreetMap 库是否支持 API 级别 8:help.openstreetmap.org/questions/13680/…
-
问题是“com.google.android.gms:play-services:6.1.71”至少需要minSdk 9.改变minSdk值解决了你的问题。
-
我正在检查 openstreetmap,我找到了我需要的东西,但找不到任何关于导入和使 osmdroid 与 android studio 一起工作的指南。有人知道分步指南吗?
标签: java android google-maps fragment mapfragment