如何在我的android studio项目上添加自己的地图图层

时间:2019-08-10 11:36:25

标签: java android geojson

我正在开发一个应用程序,必须在该应用程序上进行地图绘制,在底图上添加一个图层。我正在使用google map作为我的基本地图。我将图层保存为geojson格式。但是我的代码无法正常工作。我是android studio的新手。我在使用geojson文件时遇到问题。我使用的是我存储在资源文件中的geojson原始格式...我是否必须读取所有文件,然后仅呈现它们或什么

public abstract class MapsActivity extends abc implements 
OnMapReadyCallback, map{

private GoogleMap mMap;
private GeoJsonLayer layer;
private Context context;

public void JSON(Context context) {
    this.context = context;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

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


@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in 
Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
public class Myclass extends AsyncTask<GoogleMap,Void,GeoJsonLayer> implements com.example.jpt.Myclass{

    @Override
    protected GeoJsonLayer doInBackground(GoogleMap... googleMaps) {
        GeoJsonLayer layer = null;

        try {
            layer = new GeoJsonLayer(mMap, R.raw.abc, context);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return layer;
    }

    @Override
    public void postexe(){
        layer.addLayerToMap();
    }

    }
}





public abstract class MapsActivity extends abc implements 
OnMapReadyCallback, map{

private GoogleMap mMap;
private GeoJsonLayer layer;
private Context context;

public void JSON(Context context) {
    this.context = context;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

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


/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
public class Myclass extends AsyncTask<GoogleMap,Void,GeoJsonLayer> implements com.example.jpt.Myclass{

    @Override
    protected GeoJsonLayer doInBackground(GoogleMap... googleMaps) {
        GeoJsonLayer layer = null;

        try {
            layer = new GeoJsonLayer(mMap, R.raw.abc, context);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return layer;
    }

    @Override
    public void postexe(){
        layer.addLayerToMap();
    }

    }
}

当我运行此程序时,出现一条消息,提示我的应用已停止工作

0 个答案:

没有答案