Import KML in Maps API V2

前端 未结 2 2038
一向
一向 2021-01-13 08:06

I have multiple KML files which are drawn in google earth and contain different routes. Now I\'m trying to display those in my android project with Maps API V2.

Is t

相关标签:
2条回答
  • 2021-01-13 08:29

    Just an update on the KML library for Maps API V2 part of the question. There is now a beta available of Google Maps KML Importing Utility.

    It is part of the Google Maps Android API Utility Library. As documented it allows loading KML files from streams

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

    or local resources

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

    After you have created a KmlLayer, call addLayerToMap() to add the imported data onto the map.

    layer.addLayerToMap();
    
    0 讨论(0)
  • 2021-01-13 08:36

    For now Ill just assume that theres no public library that does this for us so I'm going to use Google's code to add polylines and polygons to my map after parsing the data in my KML file. Will update this answer if a library is found.

    Create Polylines and Polygons:

    // Instantiates a new Polyline object and adds points to define a rectangle
    PolylineOptions rectOptions = new PolylineOptions()
            .add(new LatLng(37.35, -122.0))
            .add(new LatLng(37.45, -122.0))  // North of the previous point, but at the same longitude
            .add(new LatLng(37.45, -122.2))  // Same latitude, and 30km to the west
            .add(new LatLng(37.35, -122.2))  // Same longitude, and 16km to the south
            .add(new LatLng(37.35, -122.0)); // Closes the polyline.
    
    // Set the rectangle's color to red
    rectOptions.color(Color.RED);
    
    // Get back the mutable Polyline
    Polyline polyline = myMap.addPolyline(rectOptions);
    
    0 讨论(0)
提交回复
热议问题