我正在尝试在地图上添加一个2000个位置的图层。代码应该正常工作,它显示了添加KML图层的try块,但地图上没有显示任何内容。
在进一步检查时,我相信它必须是我在谷歌地图中生成的KML文件的问题。这是因为我下载的示例KML文件工作得很好,而不是我生成的那个?
public class MapsActivity extends FragmentActivity实现了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>}
答案 0 :(得分:1)
对于有此问题的其他人,谷歌可以从地址的csv文件创建一个KML文件,但它无法读取它。您必须先将csv文件中的地址转换为lat / long,然后再创建kml文件。