user7437489
user7437489

Reputation: 41

Getting coordinates of a placemark from kml

I want to do some computations for distance between the user's current location and the placemarks on the map (which is loaded from a kml file) but in order to do that I need to access the markers' locations from the kml file. I tried to do that by:

 for (KmlContainer container : layer.getContainers()) {
        if (container.hasProperty("coordinates")) {
            LatLng from = (container.getProperty("coordinates"));

But (container.getProperty("coordinates")) actually returns a string apparently. Is there a way I can get the coordinates as a LatLng?

Upvotes: 1

Views: 1650

Answers (1)

Alan Pachuau
Alan Pachuau

Reputation: 61

I believe this is what you need to get the coordinate as LatLng. The Java code below is for Android.

for(KmlPlacemark placemark: kmlLayer.getPlacemarks()) {
    if(placemark.getGeometry().getGeometryType().equals("Point")) {
        KmlPoint point = (KmlPoint) placemark.getGeometry();
        LatLng latLng = new LatLng(point.getGeometryObject().latitude, point.getGeometryObject().longitude);
    }
}

Upvotes: 2

Related Questions