2017-08-10 75 views
0

我一直在尋找這個星期的答案,所以請原諒,如果我看起來有點沮喪。這是因爲我。Android |將導航抽屜添加到默認地圖活動

提前,對不起,如果這個問題之前已被問過。我是Android新手(我主要做網絡應用程序),對我來說這是一個全新的世界。所有幫助表示讚賞!

我想要做的是添加一個導航抽屜到mill maps活動的標準運行。我會如何去做這件事?我希望每個按鈕都能夠將地圖重新​​映射到另一個地方。

雖然我們在這裏,但我打算在地圖上創建一個KML圖層。如您所知,KML點內置了信息,因此當您點擊/點擊它們時,您可以看到信息。我想讓KML點使用其內置信息打開導航抽屜。我很好用這個默認的Android點,但與KML東西讚賞。如果你想要一個參照系,認爲像這樣的JavaScript的例子,但與隱藏的大部分時間側邊欄:https://developers.google.com/maps/documentation/javascript/kml

MainActivity.java:

package us.tourismproject.jared.tourismprojectandroid; 

import android.content.res.Resources; 
import android.nfc.Tag; 
import android.support.v4.app.FragmentActivity; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.util.Log; 

import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.OnMapReadyCallback; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MapStyleOptions; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class MainActivity extends AppCompatActivity implements OnMapReadyCallback { 

private static final String TAG = MainActivity.class.getSimpleName(); 

private GoogleMap mMap; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    // 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); 
} 


/** 
* Manipulates the map once available. 
* This callback is triggered when the map is ready to be used. 
* This is where we can add markers or lines, add listeners or move the camera. In this case, 
* we just add a marker near Sydney, Australia. 
* If Google Play services is not installed on the device, the user will be prompted to install 
* it inside the SupportMapFragment. This method will only be triggered once the user has 
* installed Google Play services and returned to the app. 
*/ 
@Override 
public void onMapReady(GoogleMap googleMap) { 
    mMap = googleMap; 

    try { 
     // Customise the styling of the base map using a JSON object defined 
     // in a raw resource file. 
     boolean success = googleMap.setMapStyle(
       MapStyleOptions.loadRawResourceStyle(
         this, R.raw.style_json)); 

     if (!success) { 
      Log.e(TAG, "Style parsing failed."); 
     } 
    } catch (Resources.NotFoundException e) { 
     Log.e(TAG, "Can't find style. Error: ", e); 
    } 
    // Position the map's camera near Sydney, Australia. 
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(-34, 151))); 
} 
} 

activity_main.xml中

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:map="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/map" 
android:name="com.google.android.gms.maps.SupportMapFragment" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="us.tourismproject.jared.tourismprojectandroid.MainActivity" /> 

感謝您的任何幫助提前。現在好日子!

+0

你想要什麼?您想在MainActivity中添加導航抽屜 –

回答

0

首先,您需要將Fragment包裝在另一個父級佈局中,其中包括Navigation drawer,然後在java中爲drawer設置事物。 參考this

來到交互部分,KML只是一個符號,它擁有一些信息,你所能做的就是爲每一個KML地理點,並把它綁的點擊功能打開Navigation drawer

Check here添加標記到谷歌地圖

+0

我將如何着手創建所有KML點的點擊功能?我對Java/Android的知識非常有限。儘管我有地圖工作,所以對你很讚賞。 –

+1

想通了!我使用OnMarkerClickListener創建一個onMarkerClick布爾值,它檢查哪個標記被點擊。然後它打開一個單獨的片段。感謝所有幫助的人! –

+0

很高興我能幫忙:) –

0

如果你想抽屜式導航欄在你的地圖活動比更新activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" android:layout_height="match_parent" 
     android:fitsSystemWindows="true" tools:openDrawer="start"> 

     <fragment 
      android:id="@+id/map" 
      android:name="com.google.android.gms.maps.SupportMapFragment" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
    tools:context="us.tourismproject.jared.tourismprojectandroid.MainActivity" /> 

     <android.support.design.widget.NavigationView android:id="@+id/nav_view" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:fitsSystemWindows="true"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 

       <!-- Draw your view whatever you want to draw --> 

      </LinearLayout> 


     </android.support.design.widget.NavigationView> 

    </android.support.v4.widget.DrawerLayout> 

它將創建您的導航抽屜一個答案通過提拉詹,你需要編寫一些代碼來處理導航抽屜。