标签: android-maps-v2

旋转后,MapFragment变得无法响应

我的问题很简单,我将4个FrameLayout添加到我的XML中,并在这些容器中按代码添加4个MapFragment.

像这样 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:map="http://schemas.android.com/apk/res-auto"
  android:id="@+id/map_container"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:orientation="horizontal">
    <FrameLayout
      android:id="@+id/map1_container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_weight="0.5""/>
    <FrameLayout
      android:id="@+id/map2_container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_weight="0.5"/>
  </LinearLayout>
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:orientation="horizontal">
    <fragment
      android:id="@+id/map3_container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_weight="0.5"/>
    <fragment
      android:id="@+id/map4_container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_weight="0.5""/>
  </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在我的活动中

public class MultiGoogleMapActivity extends FragmentActivity {

    private GoogleMap mMap;
    private GoogleMap mMapUp;
    private GoogleMap mMapMiddle;
    private GoogleMap mMapLow;

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

mMap1Fragment = SupportMapFragment.newInstance();
    FragmentTransaction fragmentTransaction = getSupportFragmentManager()
                        .beginTransaction();
                fragmentTransaction.add(R.id.map1_container, mMap1Fragment, MAP_FRAGMENT_TAG); …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-maps-v2

3
推荐指数
1
解决办法
1100
查看次数

android中的彩色折线映射api v2

我想在android maps api版本2中绘制折线.我希望它有很多颜色,最好是渐变色.在我看来,折线只允许单色.我怎样才能做到这一点?我已经有api-v1叠加绘制我喜欢的东西,所以我可以重用一些代码

public class RouteOverlayGoogle extends Overlay {
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
       //(...) draws line with color representing speed
    }
Run Code Online (Sandbox Code Playgroud)

android linear-gradients polyline android-maps-v2

3
推荐指数
1
解决办法
2603
查看次数

标记位置更改的事件

我正在使用新版Google Maps for Android v2.有没有办法为标记位置变化设置监听器?例如,当用户拖动标记时.

android android-maps android-maps-v2

3
推荐指数
1
解决办法
5639
查看次数

在Android中的谷歌地图v2中缩放移动捏合侦听器

我正在Android APP中使用地图v2

我的地图每隔几秒自动更新一次,以在地图上显示一些新点.每次刷新时,自动执行以下事件:调用"setOnCameraChangeListener".

用户可以通过移动相机或进行缩放来与地图交互.我需要在地图上拦截用户的手势,例如"缩放","拖动","捏合打开"或"捏合".

所以我不能使用"OnCameraChangeListener",因为这已经在应用程序自动更新数据时自动完成,我无法理解事件发生时自动更新地图或何时通过用户交互

如何捕获这些用户手势?

android gesture android-maps-v2

3
推荐指数
1
解决办法
2422
查看次数

android地图,标记和内存泄漏

我正在阅读android文档 http://developer.android.com/reference/com/google/android/gms/maps/MapFragment.html ,我遇到了这句话:

从GoogleMap获取的任何对象都与视图相关联.重要的是不要在视图的生命之外保持对象(例如标记).否则会导致内存泄漏,因为视图无法释放.

我不完全理解这一点,我不确定它是否适用于我,但我只是想检查一下:这只适用于主视图仍然存在时片段被破坏的情况,对吧?我的地图片段是该布局的xml中唯一的元素,因此我假设当用户导航时,标记对象(以及其他所有内容)都会被破坏.我是对的,还是相反?

java android google-maps memory-leaks android-maps-v2

3
推荐指数
1
解决办法
2351
查看次数

Android - Google Maps Extensions - IllegalArgumentException

当我调用这个createMarker()方法时,我得到一个IllegalArgumentException:

private void createMarker(GoogleMap map, MarkerOptions options, OnMarkerCreateListener listener) {
    Log.e("LazyMarker", "Options var val: "+options);
    Log.i("LazyMarker", "GoogleMap Value:"+map);
    Log.i("LazyMarker", "OnMarkerCreateListener Value:"+listener);
    marker = map.addMarker(options);
    //Log.i("LazyMarker", "The value of Marker is:"+map.addMarker(options));
    if (listener != null) {
        listener.onMarkerCreate(this);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是logcat输出:

06-14 11:40:38.627: I/OGT.RideTracking(25590): Map value is: com.google.android.gms.maps.GoogleMap@4249bd30
06-14 11:40:38.627: E/LazyMarker(25590): Options var val: com.google.android.gms.maps.model.MarkerOptions@4318baf8
06-14 11:40:38.627: I/LazyMarker(25590): GoogleMap Value:com.google.android.gms.maps.GoogleMap@4249bd30
06-14 11:40:38.627: I/LazyMarker(25590): OnMarkerCreateListener Value:null
06-14 11:40:38.637: D/AndroidRuntime(25590): Shutting down VM
06-14 11:40:38.637: W/dalvikvm(25590): threadid=1: thread exiting with uncaught exception (group=0x415d7438)
06-14 …
Run Code Online (Sandbox Code Playgroud)

java android google-maps-android-api-2 android-maps-v2 android-maps-extensions

3
推荐指数
1
解决办法
2780
查看次数

API Maps v2的自定义信息窗口中的RelativeLayout宽度

我有一个Google Maps API v2的自定义信息窗口,它使用通过在我的班级覆盖getInfoWindow添加的RelativeLayout.这个布局有一个TextView,第一行有一个标题,下一行有三个TextView,一个对齐到左边,另一个对齐到中心,第三个对齐到右边.它可以工作,但窗口占据了整个屏幕,这在平板电脑等大屏幕上非常难看.

我试图将RelativeLayout的宽度设置为某个固定值(比如说"50dp")或"wrap_content",但它总是需要整个屏幕.

这是布局的XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/bus_stop_info_window"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#ffffffff" >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:text="A title" >
    </TextView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"
        android:gravity="left"
        android:text="Test1" >
    </TextView>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"
        android:gravity="center"
        android:text="Test2" >
    </TextView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"
        android:gravity="left"
        android:text="Test3" >
    </TextView>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我怎样才能达到预期的效果?

maps android relativelayout android-maps-v2

3
推荐指数
1
解决办法
3774
查看次数

Android谷歌地图错误android.view.InflateException:二进制XML文件行#6:错误启动类片段

因此,在对同一错误执行了大约15个不同的堆栈溢出问题之后,我还有另一个关于无法启动活动ComponentInfo的问题.

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


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

    <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Required to show current location -->
    <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" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.hauntingongrounds.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.gms.version"
            android:value="AIzaSyAI********************-EhL8Ys" />
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

以上是清单.以下是XML和主要活动.

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment; …
Run Code Online (Sandbox Code Playgroud)

java xml android google-maps android-maps-v2

3
推荐指数
1
解决办法
9749
查看次数

findFragmentById(R.id.map)在Android L中返回null

在Android 4.4中测试基于位置的应用时,我们能够通过Android地图v2正确查看和使用地图

自从我升级到Android L以来,它无法使用以下代码获取MapFragment:

  1. 在MainActivity中有一个FrameLayout,我在其中加载ShowMapFragment.

  2. 在ShowMapFragment中有一个MapFragment来显示地图.

  3. 在'OnCreateView()'方法内 mapFragment = (MapFragment)getFragmentManager().findFragmentById(R.id.map); map = mapFragment.getMap();

mapFragment将为null.对此有何帮助?

android google-maps google-play-services android-maps-v2 android-5.0-lollipop

3
推荐指数
1
解决办法
2019
查看次数

getMapAsync() - 调用一次并保存结果,或者每次需要地图时调用?

Google Play Services 6.5添加了该getMapAsync方法,该方法允许我们异步检索GoogleMap支持MapFragment(或MapView)的对象.文件说明了这一点

回调提供的GoogleMap对象为非null.

我对这里为什么需要异步检索没有很好的理解(即,什么情况可能导致被弃用的getMap方法返回null),这引出了以下问题:

当使用a时MapFragment,我应该调用getMapAsync一次onCreate,存储GoogleMap回调返回的(非null),然后在我的类中的其他地方引用这个存储的结果吗?或者,我是否应该getMapAsync每次需要与GoogleMap对象进行交互时调用,并在相应的回调中执行所有与地图相关的工作?

第一个选项导致更紧凑的代码,所以我更愿意尽可能使用它.GoogleMap我存储的对象是否存在"陈旧"或null(在这种情况下第二个选项会更安全)的风险是否存在?

android google-maps google-play-services android-maps-v2

3
推荐指数
1
解决办法
1330
查看次数