我一直在尝试从http://androider.blogspot.in/2013/01/google-maps-android-api-v2-example_3.html
编写MAP活动代码但是,我在
中遇到错误 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.OnMapLongClickListener;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
它也不可能添加上面提到的导入以及GoogleMap类。 任何人都可以帮助我摆脱这个问题,对于安卓和学习我自己来说都是新手。
答案 0 :(得分:2)
您需要拥有Google Play服务库项目。你可以从你的android sdk(路径:basepath + android-sdks \ extras \ google \ google_play_services \ libproject)获取它。在这个项目的libs文件夹中,你将获得一个名为“google-play-services.jar”的jar文件。将此jar文件放入项目libs文件夹,并将google play服务库项目导入您的工作区并将其添加到您的项目中(更安全的一面)。我认为它会对你有帮助。
答案 1 :(得分:0)
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import com.google.android.gms.maps.CameraUpdateFactory;
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.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class FindUsActivity extends android.support.v4.app.FragmentActivity {
GoogleMap find_us_map;
ImageButton btn_home;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_findus);
SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.activity_findus_map);
find_us_map = fragment.getMap();
find_us_map.setMyLocationEnabled(true);
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.title("Town Tour");
markerOptions.snippet("We are here");
LatLng latlng = new LatLng(40.4230, 98.7372);
find_us_map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 4));
find_us_map.animateCamera(CameraUpdateFactory.zoomTo(4), 2000, null);
markerOptions.position(latlng);
Marker m = find_us_map.addMarker(markerOptions);
btn_home = (ImageButton) findViewById(R.id.activity_findus_ibtn_home);
btn_home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/activity_findus_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.example.towntour.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.towntour.android.maps.googlev2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.temp.android.maps.googlev2.permission.MAPS_RECEIVE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDp6PHK3NYNwS74cKGdfgdmX-xc4LuH_uM1mIo" />