我正在将我现有的谷歌地图代码(大部分是在我选择Android Studio中的“谷歌地图活动”时生成的)转换为Android扩展库,以便使用这个库中的标记集群和使用Android扩展开发的重叠标记蜘蛛工具。
现在,我对这个方法有一个问题(我使它比我现有的方法更小,以便于阅读,所以如果有任何错误,请让我知道,我会编辑它):
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 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;我将android:name从"android:name="com.google.android.gms.maps.SupportMapFragment“改为"com.androidmapsextensions.SupportMapFragment”in 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" />另外,这些是我的Gradle文件中的依赖项:
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'
}但仍然收到同样的错误信息。有什么东西我忘了换,或者我需要加些什么?
如果你想知道更多的信息,请在下面留下评论,我会回复或编辑这篇文章。
发布于 2015-01-08 15:25:36
您必须使用getExtendedMap,而不是从Android v2迁移中描述的getMap (或getExtendedMapAsync)。
请注意,去聚类或重叠标记蜘蛛,如您在演示应用程序中称为它还没有生产准备好,您将不得不调整它,所以它不会崩溃。
完全公开:我是Android扩展开发人员。
https://stackoverflow.com/questions/27842526
复制相似问题