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.
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:
<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:
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.
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.
Full disclosure: I'm Android Maps Extensions developer.