在我的应用中,我希望用户在Google地图中提供他们想要的内容.所以,首先我创建了一个带有按钮的活动,供用户打开谷歌地图:
private Button.OnClickListener opengmap = new Button.OnClickListener() {
public void onClick(View v) {
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
Toast.makeText(v.getContext(), v.getContext().getString(R.string.T1001_NoGPSDetection), Toast.LENGTH_LONG).show();
} else {
strprovider = locationManager.getBestProvider(criteria, false);
location = locationManager.getLastKnownLocation(strprovider);
}
**gmap = new GM001MapForAddress(v.getContext(), location.getLatitude(), location.getLongitude(), R.id.map);
gmap.initialize();**
}
};
Run Code Online (Sandbox Code Playgroud)
然后,我有这个GM001MapForAddress初始化谷歌地图,旨在有一个可拖动的标记:
public class GM001MapForAddress {
public Context context;
public GoogleMap googleMap;
public MarkerOptions markeroption;
public Marker marker;
public CameraUpdate center;
public Double latitude, longitude;
public Integer id;
public Activity activity;
public GM001MapForAddress(Context …Run Code Online (Sandbox Code Playgroud)