-3

我一直在尝试从 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 类。任何人都可以帮助我摆脱这个,我对 android 和学习我自己很陌生。

4

2 回答 2

2

您需要拥有 Google Play Services 库项目。您可以从您的 android sdk 中获取它(路径:basepath+android-sdks\extras\google\google_play_services\libproject)。在这个项目的 libs 文件夹中,您将获得一个名为“google-play-services.jar”的 jar 文件。将此 jar 文件放入您的项目 libs 文件夹中,并将 google play services 库项目导入您的工作区并将其添加到您的项目中(为了更安全)。我想它会对你有所帮助。

于 2013-08-21T11:45:49.573 回答
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" />
于 2013-08-21T11:27:43.387 回答