6

मैं पोलीलाइंस लेकिन गूगल मानचित्र पर दिशा के साथ तीर जोड़ने के लिए enter image description hereएंड्रॉयड ड्रा पोलीलाइंस

नीचे के रूप में प्रदर्शन किया जाना चाहिए और जब यह ऊपर ज़ूम, और अधिक तीर प्रदर्शन किया जाना चाहिए में सक्षम नहीं जोड़ा है जैसे enter image description here नीचे

मैं विभिन्न ब्लॉग्स और कोड नहीं बल्कि लक्ष्य

मैं नीचे कोड स्निपेट निम्नलिखित का इस्तेमाल किया है प्राप्त करने में सक्षम पढ़ने की कोशिश की है:

private void DrawArrowHead(MarkerOptions MO, GoogleMap mMap, LatLng from, LatLng to) { 
     // obtain the bearing between the last two points 
     double bearing = GetBearing(from, to); 

     // round it to a multiple of 3 and cast out 120s 
     double adjBearing = Math.round(bearing/3) * 3; 
     while (adjBearing >= 120) { 
      adjBearing -= 120; 
     } 

     StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
     StrictMode.setThreadPolicy(policy); 

     // Get the corresponding triangle marker from Google 
     URL url; 
     Bitmap image = null; 

     try { 
      url = new URL("http://www.google.com/intl/en_ALL/mapfiles/dir_" + String.valueOf((int) adjBearing) + ".png"); 
      try { 
//    image = BitmapFactory.decodeStream(url.openConnection().getInputStream()); 
       Log.d("HistoryDisplay", String.valueOf(adjBearing)); 
//    image = BitmapFactory.decodeResource(getResources(), R.drawable.arrow); 
       image = BitmapFactory.decodeResource(getResources(), allArrow.get((int) adjBearing)); 
      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } catch (MalformedURLException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     if (image != null) { 

      // Anchor is ratio in range [0..1] so value of 0.5 on x and y will center the marker image on the lat/long 
      float anchorX = 0.5f; 
      float anchorY = 0.5f; 

      int offsetX = 0; 
      int offsetY = 0; 

      // images are 24px x 24px 
      // so transformed image will be 48px x 48px 

      //315 range -- 22.5 either side of 315 
      if (bearing >= 292.5 && bearing < 335.5) { 
       offsetX = 24; 
       offsetY = 24; 
      } 
      //270 range 
      else if (bearing >= 247.5 && bearing < 292.5) { 
       offsetX = 24; 
       offsetY = 12; 
      } 
      //225 range 
      else if (bearing >= 202.5 && bearing < 247.5) { 
       offsetX = 24; 
       offsetY = 0; 
      } 
      //180 range 
      else if (bearing >= 157.5 && bearing < 202.5) { 
       offsetX = 12; 
       offsetY = 0; 
      } 
      //135 range 
      else if (bearing >= 112.5 && bearing < 157.5) { 
       offsetX = 0; 
       offsetY = 0; 
      } 
      //90 range 
      else if (bearing >= 67.5 && bearing < 112.5) { 
       offsetX = 0; 
       offsetY = 12; 
      } 
      //45 range 
      else if (bearing >= 22.5 && bearing < 67.5) { 
       offsetX = 0; 
       offsetY = 24; 
      } 
      //0 range - 335.5 - 22.5 
      else { 
       offsetX = 12; 
       offsetY = 24; 
      } 

      Bitmap wideBmp; 
      Canvas wideBmpCanvas; 
      Rect src, dest; 

      // Create larger bitmap 4 times the size of arrow head image 
      wideBmp = Bitmap.createBitmap(image.getWidth() * 2, image.getHeight() * 2, image.getConfig()); 

      wideBmpCanvas = new Canvas(wideBmp); 

      src = new Rect(0, 0, image.getWidth(), image.getHeight()); 
      dest = new Rect(src); 
      dest.offset(offsetX, offsetY); 
      wideBmpCanvas.drawBitmap(image, src, dest, null); 
//   MO.position(to); 
      MO.icon(BitmapDescriptorFactory.fromBitmap(wideBmp)); 
      MO.anchor(anchorX, anchorY); 

      mMap.addMarker(MO); 
//   mMap.addMarker(new MarkerOptions() 
//     .position(to) 
//     .icon(BitmapDescriptorFactory.fromBitmap(wideBmp)) 
//     .anchor(anchorX, anchorY)); 
     } 

    } 

    private double GetBearing(LatLng from, LatLng to) { 
     double lat1 = from.latitude * Math.PI/180.0; 
     double lon1 = from.longitude * Math.PI/180.0; 
     double lat2 = to.latitude * Math.PI/180.0; 
     double lon2 = to.longitude * Math.PI/180.0; 

     // Compute the angle. 
     double angle = -Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2), Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2)); 

     if (angle < 0.0) 
      angle += Math.PI * 2.0; 

     // And convert result to degrees. 
     angle = angle * degreesPerRadian; 

     return angle; 
    } 
+1

आपका कोड कहां है? आपने क्या प्रयास किया है क्या यह एंड्रॉइड एपीआई या जावास्क्रिप्ट एपीआई है? – MrUpsidown

+0

इसकी एंड्रॉइड एपीआई – Yagnesh

उत्तर

4

तीरहेड खींचने का सबसे अच्छा तरीका मानचित्र पर 'Marker' का उपयोग करना है और इसे लाइन के अंत या प्रारंभ बिंदु के समान ही रखना है। आपको इसे सपाट बनाने और मैन्युअल रूप से इसके घूर्णन को सेट करने की आवश्यकता होगी।

सौभाग्य से, Google मानचित्र उपयोग शीर्षक (रोटेशन) की गणना करने में सहायता कर सकते हैं।

बस संकलन 'com.google.maps.android:android-maps-utils:0.3.4' अपने build.gradle फ़ाइल में एक निर्भरता के रूप में जोड़ने के

public static void double computeHeading(LatLng from, LatLng to) 

उपयोग Double HeadingRotation = SphericalUtil.computeHeading(LatLng from, LatLng to)

मार्कर रोटेशन के रूप में मान (जो डिग्री में है) सेट करें।

तीरहेड एक साधारण बिटमैप हो सकता है, या बेहतर एक ड्रॉबल Shape भी हो सकता है।

यह भी देखें: Google Map Android API Utility

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