您好我想在我的应用上添加google map api。但是有一个
无法找到com.google.android.gms.maps.Supportmapfragment类
错误,我无法找到解决方案。我从stackoverflow中浏览了其他问题。但是它们不是我问题的正确解决方案。 这是我的代码:
Map.java
import com.google.android.gms.maps.GoogleMap;
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 Map extends FragmentActivity {
private GoogleMap googleHarita;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
if (googleHarita == null) {
googleHarita = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.haritafragment))
.getMap();
if (googleHarita != null) {
//İstanbul, Kız Kulesi olsun.
LatLng istanbulKoordinat = new LatLng(41.021161,29.004065);
googleHarita.addMarker(new MarkerOptions().position(istanbulKoordinat).title("Kız Kulesi"));
googleHarita.moveCamera(CameraUpdateFactory.newLatLngZoom(istanbulKoordinat, 13));
}
}
}
map.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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.mimarasistan.Map" >
<fragment
android:id="@+id/haritafragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
清单文件:
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="16" />
<permission
android:name="com.example.mimarasistan.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Required to show current location -->
<!-- Cihazdan Google Servislerine erişmek için izin -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="com.example.mimarasistan.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Map"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
<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="my_api_key" />
</application>
</manifest>
我还添加了google play service lib。我不明白错误的原因。请帮忙!感谢
答案 0 :(得分:0)
问题在于您将google-play-services添加到项目中的方式:
阅读我写的这篇博客文章的前三个步骤,以了解如何正确地做到这一点:
Google Maps API V2
简而言之,您应该将google-play-services导入工作区中的项目。然后从你的项目中引用它。
答案 1 :(得分:0)
我遇到了与Android Studio相同的问题,我刚刚添加了播放服务库并且工作了。
在Android Studio中是:
档案 - &gt;项目结构 - &gt;在应用程序 - &gt;依赖性
你在绿色+中添加点击并选择&#34; com.android.android.gms&#34;