0

我已经使用mapView api2在android中为谷歌地图制作了一个应用程序,我已经尝试了以下代码。我已经做了两个标记,现在我想在标记的“片段”上点击事件......而不是在标记上..关于片段..请帮助我..

清单.xml

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
  <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="com.example.mapviewdemo.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="AIzaSyCs4iErZHkoSk2lp_ah2XH70y0qCOaMxN8" />
    </application>

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"
    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=".MainActivity" >

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

</RelativeLayout>

main.java

package com.example.mapviewdemo;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

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

    }

}

4

1 回答 1

2

确保您已按照以下链接中的所有步骤操作

https://developers.google.com/maps/documentation/android/start

在清单文件中添加以下内容

 <permission
    android:name="com.example.mapviewdemo.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"/>
 <uses-permission android:name="com.example.mapviewdemo.permission.MAPS_RECEIVE"/>

http://developer.android.com/reference/com/google/android/gms/maps/MapFragment.html

引用上述文档

仅当MapFragment您是targeting API 12 and above. 否则,使用SupportMapFragment.

您的 min sdk 为 8。您应该使用 Support Fragment。

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

您的活动必须延长FragmentActivity

SupportMapFragment fm = (SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap mMap = fm.getMap(); 

确保您已添加支持库

还要确保您导入了以下内容

import android.support.v4.app.FragmentActivity;  
import com.google.android.gms.maps.SupportMapFragment;    
于 2013-06-12T06:13:12.120 回答