Reputation: 1215
I am trying to add a layer of 2000 locations over a map. The code should be working, it shows the try block that adds the KML layer completing, but nothing shows up on the map.
On further inspection, i beleive it must be a problem with the KML file, which i generated in google maps. This is because an example KML file i downloaded works perfectly, just not the one I generated?
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private boolean gotLocation = false;
GPSTracker gps;
double latitude;
double longitude;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
Intent i = getIntent();
gps = new GPSTracker(this);
latitude = gps.getLatitude();
longitude = gps.getLongitude();
Toast.makeText(this, "WE HAVE GOT YOUR LOCATION: LATITUDE = " + latitude + "LONGITUDE = " + longitude, Toast.LENGTH_LONG).show();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMyLocationEnabled(true);
mMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("Current Position"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(latitude, longitude)));
mMap.animateCamera(CameraUpdateFactory.zoomTo(10));;
try {
KmlLayer layer = new KmlLayer(mMap, R.raw.vha, getApplicationContext());
layer.addLayerToMap();
Log.v("Maps", "We should have added layer");
} catch (XmlPullParserException e) {
e.printStackTrace();
Log.v("Maps", "Pull parser exception");
} catch (IOException e) {
e.printStackTrace();
Log.v("Maps", "IO exception");
}
}
}
<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://www.opengis.net/kml/2.2'>
<Document>
<name>VHA</name>
<description><![CDATA[]]></description>
<Folder>
<name>VHA</name>
<Placemark>
<name>Aberdeen VA Clinic</name>
<description><![CDATA[Address: 2301 8th Ave. NE, Suite 225 Aberdeen, SD 57401<br>State: SD<br>Phone: 605-229-3500<br>Zip: 57401]]></description>
<styleUrl>#icon-1899-0288D1</styleUrl>
<ExtendedData>
<Data name='Address'>
<value>2301 8th Ave. NE, Suite 225 Aberdeen, SD 57401</value>
</Data>
<Data name='State'>
<value>SD</value>
</Data>
<Data name='Phone'>
<value>605-229-3500</value>
</Data>
<Data name='Zip'>
<value>57401</value>
</Data>
</ExtendedData>
<address>2301 8th Ave. NE, Suite 225 Aberdeen, SD 57401</address>
</Placemark>}
Upvotes: 1
Views: 610
Reputation: 1215
Ok for anyone else that ever has this problem, google can create a KML file from a csv file of addresses, but it can't read it. You have to convert the addresses in csv file to lat/long first, and then create the kml file.
Upvotes: 1