2017-03-03 13 views
-3

我有一個應用程序,當前點擊一個位置後,一個標記彈出顯示其經度和緯度。如何在SQLite中保存標記位置並在該位置創建另一個活動?

**enter image description here**

我希望能夠點擊該標誌物和保存在我的SQLite數據庫的位置數據。位置保存後,我希望突出顯示Google地圖中的位置。我怎麼做?

+0

你是什麼意思突出顯示? –

+0

@ZahidRasheed @ZahidRasheed我的意思是說,在保存GPS座標後(即特定地點的經緯度,我希望地圖能夠指出該位置,並且每次地點被保存,地圖將顯示這些地方,或者突出顯示爲不同的地方你可以告訴我怎麼做,謝謝 – geek645

回答

0

請嘗試執行下面的代碼,其中MarkerInfoWindowAdapter將在點擊標記時顯示彈出窗口。

protected void onCreate(Bundle savedInstanceState) 
     {  
      setUpMap(); 
      displayLocationOnMap(); 
     } 

    private void setUpMap() 
      { 

       if (mMap == null) 
       { 
        mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapview)).getMap(); 

        if (mMap != null) 
        { 
         mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() 
         { 
          @Override 
          public boolean onMarkerClick(com.google.android.gms.maps.model.Marker marker) 
          { 
           marker.showInfoWindow(); 
           return true; 
          } 
         }); 
        } 
        else 
         Toast.makeText(getApplicationContext(), "Unable to create Maps", Toast.LENGTH_SHORT).show(); 
       } 
      } 

    private void displayLocationOnMap() 
    { 
    Marker currentMarker = null; 

       currentMarker = mMap.addMarker(new MarkerOptions() 
         .position(new LatLng(latitude, longitude)) 
.title(Location) .icon(BitmapDescriptorFactory.fromResource(R.drawable.map_view))); 

       currentMarker.isInfoWindowShown(); 
       currentMarker.setVisible(true); 
       mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude(),longitude()), 8.0f)); 

       mMap.setTrafficEnabled(true); 
       mMap.setBuildingsEnabled(true); 
       mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter()); 
    } 


public class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter 
    { 
     public MarkerInfoWindowAdapter() 
     { 
     } 

     @Override 
     public View getInfoWindow(Marker marker) 
     { 
      return null; 
     } 

     @Override 
     public View getInfoContents(Marker marker) 
     { 
      View v = getLayoutInflater().inflate(R.layout.custom_map_layout, null); 

      MyMarker myMarker = mMarkersHashMap.get(marker); 

      TextView marker_latitude = (TextView) v.findViewById(R.id.marker_latitude); 

      TextView marker_longitude = (TextView) v.findViewById(R.id.marker_longitude); 



      marker_latitude.setText("Latitude :" + latitude); 

      marker_longitude.setText("Longitude:" +longitude); 

      return v; 
     } 
    } 
+0

非常感謝你!@Ragini – geek645

0

試試下面的代碼:

@Override 
    public void setOnMarkerClickListner(Marker marker) { 
     // TODO Auto-generated method stub 
     System.out.println(" " 
       + map.getMyLocation().getLongitude()+map.getMyLocation().getLongitude()); 
    //Your code to add to database.. 
    } 

在上面的代碼

map.getMyLocation().getLongitude() 

爲您提供經度和

map.getMyLocation().getLongitude() 

給你latitude.Then你會寫你的代碼放它在你的SQLite中。 希望幫助

+0

謝謝你,雖然它的正確性,但我想從infoWindow的信息到另一個活動 – geek645

+0

你將不得不使用intent for that..use intent and intent .putextra ...反正伸手如果你需要更多的信息 – Akshay

0

使用setOnMarkerClickListner點擊標記和內部onMarkerclick方法編寫你的邏輯來保存數據庫中的經度和緯度,並使用map.add(new MarkerOptions)編寫幫助者方法在google地圖上添加標記來自分區的數據

+0

謝謝你,我會盡力 – geek645

0

您可以將它們作爲REAL值保存在帶有標識符的單個表中,然後從您想要的表中引用它們。

相關問題