【问题标题】:To put a click event on snippet of marker将点击事件放在标记片段上
【发布时间】:2013-06-08 03:57:50
【问题描述】:

我已经使用 mapView api2 在 android 中为谷歌地图制作了一个应用程序,我已经尝试了以下代码。我已经制作了两个标记,现在我想在两个标记的“sn-p”上输出点击事件.. ..不在marker上..在sn-p上..请帮帮我..

ma​​nifest.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>

ma​​in.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);

    }

}

【问题讨论】:

    标签: android android-fragments google-maps-markers google-maps-android-api-2 overlayitem


    【解决方案1】:

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

    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

    引用上述文档

    仅当您是targeting API 12 and above 时才使用此MapFragment。否则,请使用SupportMapFragment

    您的最小 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;    
    

    【讨论】:

    • 我在尝试设置 google-play-service-api lib 项目的 api 级别时遇到问题
    • 您面临的问题是什么?你在你的 android 项目中提到过 google play services library 项目吗?
    • 问题是每当我点击“android”时,我的 Eclipse 都会进入“无响应”模式......!
    • 右键单击您的项目。去属性。单击android并选择google api。我想您将库项目导入 eclipse 的方式可能存在问题
    • 我已经解决了兄弟...thanx..:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多