3

i have a simple application with Google Maps API instead and i have a KML file with 1000 marker that i want to display in the MAP of my Application.

How can i import a KML file in my map?

I use Android Studio

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


    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    mMap.setMyLocationEnabled(true);


}

2 Answers 2

3

If you want to load a KML dataset from a local resource, it's like this:

KmlLayer layer = new KmlLayer(getMap(), R.raw.kmlFile, getApplicationContext());
layer.addLayerToMap();

If you want to load a KML dataset from a local stream, it's like this:

KmlLayer layer = new KmlLayer(getMap(), kmlInputStream, getApplicationContext());
layer.addLayerToMap();

More details in the Maps Andriod API documentation.

Sign up to request clarification or add additional context in comments.

Comments

2

You need to render the map and add a KML layer on top of it. Example:

KmlLayer kmlLayer = new KmlLayer(mMap, R.raw.coordinates, getApplicationContext());
kmlLayer.addLayerToMap();

Refer to this github sample project for the complete sample

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.