iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 26
0
    private BitmapDescriptor bitmapDescriptorFromVector(Context context,    
    @DrawableRes int vectorDrawableResourceId) {
    Drawable background = ContextCompat.getDrawable(context,   
    vectorDrawableResourceId);
    background.setBounds(0, 0, background.getIntrinsicWidth(),    
    background.getIntrinsicHeight());
//        Drawable vectorDrawable = ContextCompat.getDrawable(context,   
    vectorDrawableResourceId);
//        vectorDrawable.setBounds(40, 20, vectorDrawable.getIntrinsicWidth() +  
    40, vectorDrawable.getIntrinsicHeight() + 20);
    Bitmap bitmap = Bitmap.createBitmap(background.getIntrinsicWidth(),    
    background.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    background.draw(canvas);
//        vectorDrawable.draw(canvas);
    return BitmapDescriptorFactory.fromBitmap(bitmap);
    }
  • 轉換圖片

按鈕事件



     mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
         @Override
         public boolean onMarkerClick(Marker marker) {
             Intent intent = getIntent();
             double lat = intent.getDoubleExtra("lat", 0.0);
             double lng = intent.getDoubleExtra("lng", 0.0);
             if (lat != 0.0 && lng != 0.0) {
                 final DialogInterface.OnClickListener listener =
                          new DialogInterface.OnClickListener() {
                          @Override
         public void onClick(DialogInterface dialog, int which) {
                          switch (which) {
                          // 更新位置資訊
                          case DialogInterface.BUTTON_POSITIVE:
                          // 連線到Google API用戶端
                          if (!googleApiClient.isConnected()) {
                          googleApiClient.connect();
                          }
                          break;
                          // 清除位置資訊
                          case DialogInterface.BUTTON_NEUTRAL:
                          Intent result = new Intent();
                          result.putExtra("lat", 0);
                          result.putExtra("lng", 0);
                          setResult(Activity.RESULT_OK, result);
                          finish();
                          break;
                          // 取消
                          case DialogInterface.BUTTON_NEGATIVE:
                          break;
                          }
                          }
                          };
                 if (marker.equals(itemMarker)) {
                     AlertDialog.Builder ab = new       
                     AlertDialog.Builder(MapsActivity.this);

               ab.setTitle(R.string.title_update_location)
               .setMessage(R.string.message_update_location)
               .setCancelable(true);

               ab.setPositiveButton(R.string.update, listener);
               ab.setNeutralButton(R.string.clear, listener);
               ab.setNegativeButton(android.R.string.cancel, listener);

                     ab.show();
                 }
             }
             // 如果是目前位置標記
             else if (marker.equals(currentMarker)) {
                 AlertDialog.Builder ab = new 
                 AlertDialog.Builder(MapsActivity.this);

                 ab.setTitle(R.string.title_current_location)
                 .setMessage(R.string.message_current_location)
                 .setCancelable(true);

                 ab.setPositiveButton(android.R.string.ok, new 
                 DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialog, int which) {
                     Intent result = new Intent();
                     result.putExtra("lat", currentLocation.getLatitude());
                     result.putExtra("lng", 
                     currentLocation.getLongitude());
                     setResult(Activity.RESULT_OK, result);
                         finish();
                     }
                 });
             ab.setNegativeButton(android.R.string.cancel, null);

                 ab.show();

                 return true;
             }

             return false;
         }
     });

上一篇
GoogleMap-02
下一篇
[DAY27]GoogleMap連接方法
系列文
Java 與 Kotlin 入門30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言