0

我将现有的Google地图代码(其中大部分代码是在Android Studio中选择“Google地图活动”时生成的)转换为Android地图扩展库以便使用属于该库一部分的Marker Clustering和使用Android-Map-Extensions开发的Overlapping Marker Spiderfier工具。Android-Maps-Extensions使用MapFragment生成错误

现在,我有这种方法的问题(我把它比我的实际现有的方法更小,使其更容易阅读,所以如果有任何错误,请让我知道,我会编辑):

private void setUpMapIfNeeded() { 
     // Do a null check to confirm that we have not already instantiated the map. 
     if (mMap == null) { 
      // Try to obtain the map from the SupportMapFragment. 
      mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) 
        .getMap(); //ERROR IS HERE 
      // Check if we were successful in obtaining the map. 
      if (mMap != null) { 
       setUpMap(); 
      } 
     } 
    } 

基本上行:

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

正在生成一个消息,说

Incompatible Types: 
Required: com.androidmapsextensions.GoogleMap 
Found: com.google.android.gms.maps.GoogleMap 

这里是我的import语句(我包括所有的人,以防万一,包括目前注释掉的):从名字:

import android.content.Intent; 
import android.net.Uri; 
import android.support.v4.app.FragmentActivity; 
import android.os.Bundle; 
import android.text.Html; 
import android.text.Spanned; 
import android.util.Log; 
import android.view.View; 
import android.widget.TextView; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.androidmapsextensions.*; 
//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; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

import java.io.IOException; 
import java.io.InputStreamReader; 
import java.net.HttpURLConnection; 
import java.net.URL; 

我改变机器人“机器人:名字=” com.google.android.gms .maps.SupportMapFragment”到 “com.androidmapsextensions.SupportMapFragment” 在activity_maps.xml看起来像这样:

<fragment 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:id="@+id/map" tools:context=".MapsActivity" 
    android:name="com.androidmapsextensions.SupportMapFragment" /> 

而且,这些都是在我的摇篮文件的依赖关系:

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:21.0.3' 
    compile 'com.google.android.gms:play-services:6.5.87' 
    compile 'com.androidmapsextensions:android-maps-extensions:2.0.0' 
} 

不过刚开g虽然同样的错误信息。有没有我忘记改变或我需要添加的东西?

如果你想知道更多的信息,请在下面留言,我会回复或编辑这篇文章。

+0

mMap是如何定义的? –

+0

@TimCastelijns“private GoogleMap mMap;”并在方法之外声明它。 – dunce1

+0

请确保GoogleMap的定义引用了正确的包 –

回答

0

您必须使用getExtendedMap而不是getMap(或getExtendedMapAsync),如Migration from Android API v2中所述。

请注意,您在演示应用程序中调用它的解聚集或重叠标记Spiderfier不是生产准备好的,您将不得不对其进行调整,因此它不会崩溃。

完全披露:我是Android Maps Extensions开发人员。

+0

现在getMap已被弃用 –