I am developing an Android application using the Google Maps API (v2). I want to display the borders of the country, but not the names of countries or any other information (stub card). The purpose of the application is to create the game Geography.
Considering that, as stated in the documentation, the Android Google Maps API does not support custom styles , I first thought about how to draw each one (using Polylines ). So, I searched a little Google and found the already completed Polygon approximation of all countries . It is in KML format, which is easy to import into the Google Earth application, as well as into Google Maps with some restrictions , but I could not find import methods for Android.
The country in the KML file has a format similar to the following (downloaded as csv) if the country needs only one Polygon to be submitted:
Andorra," <Polygon> <outerBoundaryIs> <LinearRing> <coordinates> 1.78172,42.569962 1.723611,42.509438 1.445833,42.601944 1.78172,42.569962 </coordinates> </LinearRing> </outerBoundaryIs> </Polygon>"
And this format, if it has more than one Polygon:
Mayotte," <MultiGeometry> <Polygon> <outerBoundaryIs> <LinearRing> <coordinates> 45.282494,-12.80417 45.262497,-12.76889 45.283051,-12.7475 45.282494,-12.80417 </coordinates> </LinearRing> </outerBoundaryIs> </Polygon> <Polygon> <outerBoundaryIs> <LinearRing> <coordinates> 45.204994,-12.84972 45.097496,-12.985834 45.078888,-12.6625 45.204994,-12.84972 </coordinates> </LinearRing> </outerBoundaryIs> </Polygon> </MultiGeometry>
At this point, the solution came to my mind:
- Parse this KML file directly in the Android application (when the Activity starts), draw each Polygon :
// Instantiates a new Polygon object and adds points to define a rectangle PolygonOptions rectOptions = new PolygonOptions() .add(new LatLng(37.35, -122.0), new LatLng(37.45, -122.0), new LatLng(37.45, -122.2), new LatLng(37.35, -122.2), new LatLng(37.35, -122.0)); myMap.addPolygon(rectOptions);
I could solve the problem, but since I needed more features, such as drawing only certain continents, this was not enough.
So, I thought it would be better (and more understandable) to convert the KML file to an XML file (and have a strong Python base, which considered XML to be pretty easy to parse) with the following structure:
<continent name="Europe"> <country name="Andorra"> //As many polygons as necessary <poligon1> //Coordinates go here </poligon1> <poligonN> //Coordinates go here </poligonN> </country> </continent>
I already know how to convert KML to XML, but Android has many parsers like DOM, SAX, XMLPull ...:
- What would be most appropriate for this case? (The KML file size is 850kB).
- Could you give some examples / hints on how I will need to make all the polygons on the continent?
Please note that this idea of ββgoing through XML is not fixed and if anyone has any other ideas, I would be glad to hear them.