Я хочу использовать карту в действии.Использование одного xml для двух действий
Теперь я объясняющий целые problem.I обладают активностью и в ней я хочу, чтобы отобразить два типа карты
- Кнопка Оранжевого Карта для любого места в части, которая находится в верхней части деятельности
- Кнопка Синей карты нарисовать ломаную линию между двумя точками в части, которая находится в верхней части деятельности
Исполнив обе задачи, но
Кнопка 1 в одной и той же деятельности БСЗ карте любого места можно показать, простирающейся класса с активностью
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(); } } }
Но не может сделать с второй кнопкой, потому что полилинии и расстояние может быть сделано только за счет расширения класса с
общественный класс Maps расширяет FragmentActivity реализует OnClickListener
Пожалуйста, предложите мне, как я могу сделать, выполнить оба в одном actiivty Скажите, пожалуйста, может быть сделано sublass ..
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>
Когда я делаю это, моя деятельность (класс) не запускается. И дает мне ошибку раздувания фрагмента в xml – patient
. Введите код вашего макета activity_main. – UrMi
PLZ CHECK NOW ... – patient