我正在我的应用程序中使用Google Map API v2
来显示地图。
我已经按照所有步骤进行了操作,以在我的应用程序中启用Google地图。
public class PinLocationOnMapView extends FragmentActivity {
private double mLatitude = 0.0, mLongitude = 0.0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SupportMapFragment fragment = SupportMapFragment.newInstance();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
}
}
如果我使用这段代码,它会显示地图,但是如果我提供我的纬度/经度值,地图瓦片就不会加载,我只能看到白色的瓷砖。
以下是上述类的onCreate()中编写的代码:
if (getIntent().getExtras() != null) {
final Bundle bundle = getIntent().getBundleExtra("LOCATION");
mLatitude = bundle.getDouble("LATITUDE");
mLongitude = bundle.getDouble("LONGITUDE");
} else {
finish();
}
GoogleMapOptions options = new GoogleMapOptions();
LatLng latLng = new LatLng(mLatitude, mLongitude);
CameraPosition cameraPosition;// = new CameraPosition(latLng, 0, 0, 0);
cameraPosition = CameraPosition.fromLatLngZoom(latLng, (float) 14.0);
options.mapType(GoogleMap.MAP_TYPE_SATELLITE).camera(cameraPosition)
.zoomControlsEnabled(true).zoomGesturesEnabled(true);
SupportMapFragment fragment = SupportMapFragment.newInstance(options);
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
此外,我有一个经纬度值列表。我想在MapFragment
上展示它们,如何在MapFragment
上展示多个标记?
我尝试使用MapView
和ItemizedOverlay
,但对我来说没有用。我相信我已经正确创建了SHA1
密钥以获取API
密钥,因为如果那样是错误的,我也无法使用MapFragment
看到地图,但如果我不传递经纬度值,我可以看到它。