2016-08-24 7 views
5

हाय वर्तमान में एक Google मानचित्र ऐप पर काम कर रहा हूं।एंड्रॉइड Google मानचित्र पॉलीगॉन सर्कल होल

enter image description here

ऐसा करने के लिए मैं पहले देश भर में एक बहुभुज ओवरले बनाने एक साथ हाइलाइट किए गए क्षेत्र के लिए इस बहुभुज के लिए एक छेद जोड़कर निम्न में से बात थी:

और मैं निम्नलिखित प्रभाव चाहते कुछ केएम त्रिज्या, ताकि ज़ूमिंग के दौरान यह घट जाए और फैल जाए।

अब मुझे पता है कि बहुभुज कैसे बनाना है;

mMap.addPolygon(new PolygonOptions().addAll(sCountryBorder).fillColor(0xcc000000)); 

अब मैं इस बहुभुज के लिए एक छेद जोड़ना चाहते हैं, लेकिन मुझे नहीं पता है कि सही त्रिज्या के साथ एक परिपत्र छेद उत्पन्न करने के लिए।

mMap.addPolygon(new PolygonOptions().addAll(sCountryBorder).fillColor(0xcc000000).addHole({CIRCULAR_HOLE})); 

मैं जानता हूँ कि यह गूगल के नक्शे में एक निश्चित त्रिज्या के साथ एक चक्र बनाने के लिए यह भी किसी भी तरह LatLng ऑब्जेक्ट की श्रृंखला में इस कन्वर्ट करने के लिए संभव है हो सकता है?

mMap.addCircle(new CircleOptions() 
         .center(newLocation) 
         .radius(mRadius.size) 
         .strokeWidth(0) 
         .fillColor(getResources().getColor(R.color.transparant))); 
+0

एक नजर डालें पर http://stackoverflow.com/questions/36030648/custom-disabled-and-blank-map-in-android/36039979#36039979 – antonio

+0

लेकिन कैसे क्या मैं मीटर में वास्तविक त्रिज्या को ध्यान में रखूंगा? – sn0ep

+0

उस उदाहरण से कोड पहले ही मीटर (150 मीटर) – antonio

उत्तर

-1

मैं इस विधि का इस्तेमाल उपयोगकर्ता के स्थान से 5000 मी त्रिज्या के साथ एक चक्र आकर्षित करने के लिए है, लेकिन मुझे लगता है कि अच्छा आपके डेमो पिक में प्रभाव पर प्रकाश डाला पाने के लिए पता नहीं है, इस प्रक्रिया में हल्के नीले रंग की पृष्ठभूमि और के साथ एक चक्र देता है एक गहरा नीला स्ट्रोक। आशा करता हूँ की ये काम करेगा!

private void drawCircle(LatLng point){ 

     // Instantiating CircleOptions to draw a circle around the marker 
     CircleOptions circleOptions = new CircleOptions(); 

     // Specifying the center of the circle 
     circleOptions.center(point); 

     // Radius of the circle 
     circleOptions.radius(5000); 

     // Border color of the circle 
     circleOptions.strokeColor(0xFF0000FF); 

     // Fill color of the circle 
     circleOptions.fillColor(0x110000FF); 

     // Border width of the circle 
     circleOptions.strokeWidth(2); 

     // Adding the circle to the GoogleMap 
     mMap.addCircle(circleOptions); 

    } 
4

दुर्भाग्यवश, Google मानचित्र लाइब्रेरी सर्कल के LatLng की सरणी नहीं प्राप्त करने देती है। तो आपको खुद को एक सर्कल खींचने की जरूरत है।

असल में, आपको एक विधि प्रदान करने की आवश्यकता है जो एक बहुभुज के लिए एक छेद (सर्कल) बनाएगा जो आपके मानचित्र को भरता है।

3 चरण हैं।

1 चरण एक ऐसी विधि का निर्माण करना है जो पूरे मानचित्र को कवर करने वाला बहुभुज बनाएगा।

private static List<LatLng> createOuterBounds() { 
    float delta = 0.01f; 

    return new ArrayList<LatLng>() {{ 
     add(new LatLng(90 - delta, -180 + delta)); 
     add(new LatLng(0, -180 + delta)); 
     add(new LatLng(-90 + delta, -180 + delta)); 
     add(new LatLng(-90 + delta, 0)); 
     add(new LatLng(-90 + delta, 180 - delta)); 
     add(new LatLng(0, 180 - delta)); 
     add(new LatLng(90 - delta, 180 - delta)); 
     add(new LatLng(90 - delta, 0)); 
     add(new LatLng(90 - delta, -180 + delta)); 
    }}; 
} 

2 कदम एक विधि है कि वृत्त के वापस आ जाएगी एक IterableLatLng साथ तैयार करना है।

private static Iterable<LatLng> createHole(LatLng center, int radius) { 
    int points = 50; // number of corners of inscribed polygon 

    double radiusLatitude = Math.toDegrees(radius/(float) EARTH_RADIUS); 
    double radiusLongitude = radiusLatitude/Math.cos(Math.toRadians(center.latitude)); 

    List<LatLng> result = new ArrayList<>(points); 

    double anglePerCircleRegion = 2 * Math.PI/points; 

    for (int i = 0; i < points; i++) { 
     double theta = i * anglePerCircleRegion; 
     double latitude = center.latitude + (radiusLatitude * Math.sin(theta)); 
     double longitude = center.longitude + (radiusLongitude * Math.cos(theta)); 

     result.add(new LatLng(latitude, longitude)); 
    } 

    return result; 
} 

3 और अंतिम चरणPolygonOptions निर्माण के लिए इन तरीकों का प्रयोग है।

static PolygonOptions createPolygonWithCircle(Context context, LatLng center, int radius) { 
    return new PolygonOptions() 
     .fillColor(ContextCompat.getColor(context, R.color.grey_500_transparent)) 
     .addAll(createOuterBounds()) 
     .addHole(createHole(center, radius)) 
     .strokeWidth(0); 
} 

मैंने एक डेमो रिपोजिटरी भी बनाई है जिसमें एक ऐप है जो आवश्यक सर्कल खींचता है। https://github.com/AntonyGolovin/Google-Map-mask। सभी आवश्यक तर्क MapHelper.java कक्षा में निहित हैं।

परिणाम:

Screenshot

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