我想在活动中使用Map。
现在我解释整个问题。我有一个活动,在其中我想显示两种类型的地图
我完成了两项任务,但
按钮1 可以通过扩展带有活动的课程来显示任何位置的bsz地图
public class Map_current_Location extends Activity {
// Google Map
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// Showing / hiding your current location
googleMap.setMyLocationEnabled(true);
// Enable / Disable zooming controls
googleMap.getUiSettings().setZoomControlsEnabled(false);
// Enable / Disable my location button
googleMap.getUiSettings().setMyLocationButtonEnabled(true);
// Enable / Disable Compass icon
googleMap.getUiSettings().setCompassEnabled(true);
// Enable / Disable Rotate gesture
googleMap.getUiSettings().setRotateGesturesEnabled(true);
// Enable / Disable zooming functionality
googleMap.getUiSettings().setZoomGesturesEnabled(true);
double latitude = 31.510586;
double longitude = 74.341245;
// Adding a marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(latitude, longitude))
.title("Hello Maps ");
// changing marker color
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
googleMap.addMarker(marker);
// Move the camera to last position with a zoom level
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(latitude,
longitude)).zoom(30).build();
googleMap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
/**
* function to load map If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
但不能使用第二个按钮,因为折线和距离只能通过使用
public class Maps extends FragmentActivity实现OnClickListener
请建议我如何在一个活动中完成两个任务 请告诉我是否可以通过子类来完成..
整个活动的XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg" >
<RelativeLayout
android:id="@+id/Map_contact_location"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/relativeLayout1_contact_location" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/Information_contact_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/Map_contact_location" >
<TextView
android:id="@+id/textView_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="ftggggggggggggggggggggggggggggggg "
android:textColor="@color/defaultTextColor" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="88dp" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1_Setting"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
android:orientation="horizontal" >
<Button
android:id="@+id/call_contact"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/phone" />
<Button
android:id="@+id/distance_map"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="12dp"
android:layout_marginLeft="12dp"
android:background="@drawable/directions_icon" />
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
</RelativeLayout>
答案 0 :(得分:0)
您好请扩展FragmentActivity,因为它也是扩展Activity。