[英]Android-Maps-Extensions Generating Error with MapFragment
I am converting my existing Google Map code (most of which, was generated when I selected "Google Maps Activity" in Android Studio) to the Android-Maps-Extensions library in order to use both a Marker Clustering which is part of this library and an Overlapping Marker Spiderfier tool developed with Android-Map-Extensions. 我将现有的Google Map代码(其中大部分是在Android Studio中选择“ Google Maps Activity”时生成的)转换为Android-Maps-Extensions库,以便同时使用该库中的标记集群和使用Android-Map-Extensions开发的重叠标记Spiderfier工具。
Right now, I have a problem with this method (I made it smaller than my actual existing method to make it easier to read so if there's any mistakes, please let me know and I will edit it): 目前,我对此方法有疑问(我将其设置为小于实际的现有方法,以使其易于阅读,因此,如果有任何错误,请告诉我,我将对其进行编辑):
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();
}
}
}
Basically the line: 基本上行:
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
is generating a message that says 正在生成一条消息,说
Incompatible Types:
Required: com.androidmapsextensions.GoogleMap
Found: com.google.android.gms.maps.GoogleMap
Here are my import statements (I included all of them just in case, including the ones currently commented out): 这是我的导入语句(为了以防万一,包括了所有当前已注释掉的语句,我将它们全部包括在内):
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;
I changed android:name from "android:name="com.google.android.gms.maps.SupportMapFragment" to "com.androidmapsextensions.SupportMapFragment" in activity_maps.xml to look like this: 我将activity_maps.xml中的android:name从“ android:name =“ com.google.android.gms.maps.SupportMapFragment”更改为“ com.androidmapsextensions.SupportMapFragment”,如下所示:
<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" />
Also, these are the dependencies in my Gradle file: 另外,这些是我的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'
}
Still getting the same error message though. 虽然仍然收到相同的错误消息。 Was there something I forgot to change or something I need to add?
是否有我忘记更改的内容或需要添加的内容?
If you want to know more information, please leave a comment below and I will respond or edit this post. 如果您想了解更多信息,请在下面发表评论,我将回复或编辑此帖子。
You'll have to use getExtendedMap
instead of getMap
(or getExtendedMapAsync
) as described in Migration from Android API v2 . 如从Android API v2迁移中所述,您必须使用
getExtendedMap
而不是getMap
(或getExtendedMapAsync
)。
Note that de-clustering or Overlapping Marker Spiderfier like you call it in demo application is not production ready and you will have to adjust it, so it doesn't crash. 请注意,像在演示应用程序中称呼的那样,去聚类或重叠标记Spiderfier尚未准备好生产,因此您必须对其进行调整,以免崩溃。
Full disclosure: I'm Android Maps Extensions developer. 全面披露:我是Android Maps Extensions开发人员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.