2013-01-23 18 views
6

पर सीमा 180 डिग्री/-180 डिग्री देशांतर (जैसे आईओएस मैपकिट) पर मैं Google मानचित्र वी 2 (एंड्रॉइड) को सीमित कर सकता हूं? मैं इसे चारों ओर लपेटना नहीं चाहता, क्योंकि मैं क्लस्टरिन एल्गोरिदम लागू करने की कोशिश कर रहा हूं, और 180/-180 डिग्री विभाजन से यह मुश्किल हो जाएगा।एंड्रॉइड मैप्स - 180 डिग्री

मैं पैनिंग चाहते हैं लाल रेखा पर सीमित होना:

enter image description here

उत्तर

3

इसलिए मैंने एक समाधान बनाया जो ठीक होना चाहिए। यदि उपयोगकर्ता -180/180 सीमा में मानचित्र को पैन करता है, तो नक्शा दूसरी ओर फ़्लिप करेगा। तो नक्शा लपेटना अभी भी संभव है, लेकिन "खतरनाक" क्षेत्र कभी प्रदर्शित नहीं होता है।

public class CustomMapView extends MapView { 

    private double prevLongitude; 

    @Override 
    public boolean onInterceptTouchEvent(MotionEvent ev) { 
     boolean retVal = correctCamera(); 
     prevLongitude = getMap().getCameraPosition().target.longitude; 
     return retVal; 
    } 

    public boolean correctCamera() {  
     if (getMap().getProjection().getVisibleRegion().latLngBounds.northeast.longitude < getMap().getProjection().getVisibleRegion().latLngBounds.southwest.longitude) { 
      double diff = getMap().getProjection().getVisibleRegion().latLngBounds.southwest.longitude - getMap().getProjection().getVisibleRegion().latLngBounds.northeast.longitude; 
      double longitudeSW; 
      double longitudeNE; 

      double longitudeDiff = (360-diff)/25; 

      // use > 0 if you want the map to jump to the other side 
      // <= 0 will cause the map to flip back 
      if (prevLongitude > 0) { 
       longitudeSW = -180 + longitudeDiff; 
       longitudeNE = -180 + longitudeDiff - diff; 
      } else { 
       longitudeSW = 180 - longitudeDiff + diff; 
       longitudeNE = 180 - longitudeDiff; 
      } 
      LatLngBounds bounds = new LatLngBounds(
             new LatLng(getMap().getCameraPosition().target.latitude, longitudeSW), 
             new LatLng(getMap().getCameraPosition().target.latitude, longitudeNE) 
           ); 
      getMap().animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0)); 

      return true; 
     } 

     return false; 
    } 
} 

और एक्सएमएल:

<com.ieffects.clustermap.CustomMapView 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

और GoogleMap के लिए (mapView.getMap()):

map.setOnCameraChangeListener(new OnCameraChangeListener() { 
    @Override 
    public void onCameraChange(CameraPosition position) { 
     mapView.correctCamera(); 
    } 
}); 

यह

मैं एक कस्टम MapView बनाने के लिए किया था यदि उपयोगकर्ता खतरनाक क्षेत्र में मानचित्र "फ्लाई" करने देता है तो इसकी आवश्यकता होती है।

1

v2 के लिए इस ट्यूटोरियल देखें: http://econym.org.uk/gmap/range.htm - मूल रूप से, आप इस कदम घटना के लिए एक श्रोता जोड़ने के लिए, और इस कदम अगर गर्भपात यह सीमा के बाहर चला जाता है। यह v3 में भी लागू होना चाहिए।

+0

लेकिन यह जेएस में है ?? –

संबंधित मुद्दे