This is the code that I have used to plot GeoJSON file in Google Maps in Android:

    mMap = googleMap;
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
    GeoJsonLayer cul_els = new GeoJsonLayer(getMap(), R.raw.cultural_elements,

I know since getMap() has been deprecated, we need to use getMapAsync() but how? When I replace the line

GeoJsonLayer cul_els = new GeoJsonLayer (getMap(),R.raw.cultural_elements,getApplicationContext());


SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

GeoJsonLayer cul_els = new GeoJsonLayer(mapFragment.getMapAsync(this), R.raw.cultural_elements,getApplicationContext());

I get an error like this:

Unhandled exceptions: java.io.IOException, org.json.JSONException

How can I make this work?


You could try to simply wrap those expression in a try-catch block:

 GeoJsonLayer cul_els = new GeoJsonLayer(map, R.raw.cultural_elements, getApplicationContext());
} catch(Exception e) {
  • when i used getMap(), it says cannot resolve method getMap(). – user2711295 Jun 23 at 6:06
  • @user2711295 I edited the answer. – philoez98 Jun 23 at 7:45
  • Now it says GeoJsonLayer() in GeoJson cannot be applied to map. – user2711295 Jun 23 at 8:29
  • Then I suggest you to read some docs and other resources to get more familiar with the libraries. My solution was about the error you posted, not the general correctness of the code. – philoez98 Jun 23 at 8:41
  • BTW you probably just need to initialize the map correctly and then pass the map object into this function, replacing the getMapAsync() function. – philoez98 Jun 23 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.