GVKun编程网logo

iphone – 将MapKit地图的缩放/边界与RouteMe地图的缩放/边界相匹配(地图边缘调整)

8

在本文中,我们将给您介绍关于iphone–将MapKit地图的缩放/边界与RouteMe地图的缩放/边界相匹配的详细内容,并且为您解答地图边缘调整的相关问题,此外,我们还将为您提供关于android–

在本文中,我们将给您介绍关于iphone – 将MapKit地图的缩放/边界与RouteMe地图的缩放/边界相匹配的详细内容,并且为您解答地图边缘调整的相关问题,此外,我们还将为您提供关于android – 位图的缩放和采样有什么区别?、Android上Google地图的缩放事件、Android上如何实现雷达图的缩放动画、baidu 地图 api 多个标签 在同一视野内显示 自动配置合适的缩放等级的知识。

本文目录一览:

iphone – 将MapKit地图的缩放/边界与RouteMe地图的缩放/边界相匹配(地图边缘调整)

iphone – 将MapKit地图的缩放/边界与RouteMe地图的缩放/边界相匹配(地图边缘调整)

编辑:我相信我的问题是这个代码适用于整数缩放级别,但我希望它适用于浮动缩放级别.

我有一个iOS应用程序,用户可以在基于RouteMe的地图和基于MapKit的地图之间切换.

当他们切换源时,我希望能够在一个中显示完全相同的区域.但是,我无法弄清楚如何使它们匹配,因为RouteMe和MapKit使用不同的数据结构来描述地图边界.

这里有一些代码可以让它有点接近,但并不准确.此代码来自:http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/

我不确定这段代码是否应该修复,或者我可能忽略了一个更简单的解决方案.代码从列出的最后一个方法开始执行:

#define MERCATOR_OFFSET 268435456
#define MERCATOR_RADIUS 85445659.44705395

#pragma mark -
#pragma mark Map conversion methods

- (double)longitudetoPixelSpaceX:(double)longitude {
  return round(MERCATOR_OFFSET + MERCATOR_RADIUS * longitude * M_PI / 180.0);
}

- (double)latitudetoPixelSpaceY:(double)latitude {
  return round(MERCATOR_OFFSET - MERCATOR_RADIUS * logf((1 + sinf(latitude * M_PI / 180.0)) / (1 - sinf(latitude * M_PI / 180.0))) / 2.0);
}

- (double)pixelSpaceXToLongitude:(double)pixelX {
  return ((round(pixelX) - MERCATOR_OFFSET) / MERCATOR_RADIUS) * 180.0 / M_PI;
}

- (double)pixelSpaceYToLatitude:(double)pixelY {
  return (M_PI / 2.0 - 2.0 * atan(exp((round(pixelY) - MERCATOR_OFFSET) / MERCATOR_RADIUS))) * 180.0 / M_PI;
}


- (MKCoordinateSpan)coordinateSpanWithMapView:(MKMapView *)mapView
                             centerCoordinate:(CLLocationCoordinate2D)centerCoordinate
                                 andZoomLevel:(NSInteger)zoomLevel {
  // convert center coordiate to pixel space
  double centerPixelX = [self longitudetoPixelSpaceX:centerCoordinate.longitude];
  double centerPixelY = [self latitudetoPixelSpaceY:centerCoordinate.latitude];

  // determine the scale value from the zoom level
  NSInteger zoomExponent = 20 - zoomLevel;
  double zoomScale = pow(2,zoomExponent);

  // scale the map’s size in pixel space
  CGSize mapSizeInPixels = mapView.bounds.size;
  double scaledMapWidth = mapSizeInPixels.width * zoomScale;
  double scaledMapHeight = mapSizeInPixels.height * zoomScale;

  // figure out the position of the top-left pixel
  double topLeftPixelX = centerPixelX - (scaledMapWidth / 2);
  double topLeftPixelY = centerPixelY - (scaledMapHeight / 2);

  // find delta between left and right longitudes
  CLLocationdegrees minLng = [self pixelSpaceXToLongitude:topLeftPixelX];
  CLLocationdegrees maxLng = [self pixelSpaceXToLongitude:topLeftPixelX + scaledMapWidth];
  CLLocationdegrees longitudeDelta = maxLng - minLng;

  // find delta between top and bottom latitudes
  CLLocationdegrees minLat = [self pixelSpaceYToLatitude:topLeftPixelY];
  CLLocationdegrees maxLat = [self pixelSpaceYToLatitude:topLeftPixelY + scaledMapHeight];
  CLLocationdegrees latitudeDelta = -1 * (maxLat - minLat);

  // create and return the lat/lng span
  MKCoordinateSpan span = MKCoordinateSpanMake(latitudeDelta,longitudeDelta);
  return span;
}


- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate
                    zoomLevel:(NSUInteger)zoomLevel
                     animated:(BOOL)animated {

  // use the zoom level to compute the region
  MKCoordinateSpan span = [self coordinateSpanWithMapView:self       
                               centerCoordinate:centerCoordinate
                                   andZoomLevel:zoomLevel];
  MKCoordinateRegion region = MKCoordinateRegionMake(centerCoordinate,span);

  // set the region like normal
  [self setRegion:region animated:animated];
}

解决方法

不幸的是,这是 Google Maps API的限制,它只在设置地图的缩放级别时接受整数值:当你设置MKMapView的显示区域时,Apple的MapKit代码调用底层的Google Maps API,结果 – 无论你使用哪种MapKit方法设置区域 – 是一个缩小到最接近的整数缩放级别的地图.

Troy Brant的代码将带您完整的循环,并在MapKit API上方放置一个图层,允许您直接设置缩放级别…但最终您无法精确控制MKMapView显示的区域,除非您想要的缩放级别map恰好是一个整数.

Stack Overflow上出现了这个问题的几个变种(例如,MKMapView setRegion “snaps” to predefined zoom levels?和MKMapView show incorrectly saved region),但到目前为止还没有人想出一种编程方式来制作具有非整数缩放级别的地图,我怀疑它需要合作谷歌与苹果之间的关系永远让它成真.

android – 位图的缩放和采样有什么区别?

android – 位图的缩放和采样有什么区别?

我在 android位图缩放和采样之间有困惑这里可能有两个代码用于缩放,另一个用于采样任何人都可以帮助我识别这两个代码的工作以及它们之间的主要区别.

缩放:

public static Bitmap getScaleBitmap(Bitmap bitmap,int newWidth,int newHeight) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth,scaleHeight);
    return Bitmap.createBitmap(bitmap,width,height,matrix,false);
}

抽样:

mImageView.setimageBitmap(decodeSampledBitmapFromresource(getResources(),R.id.myimage,100,100));

public static Bitmap decodeSampledBitmapFromresource(Resources res,int resId,int reqWidth,int reqHeight) {

    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(res,resId,options);

    options.inSampleSize = calculateInSampleSize(options,reqWidth,reqHeight);

    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(res,options);
}

public static int calculateInSampleSize(
            BitmapFactory.Options options,int reqHeight) {
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth) {

        final int halfheight = height / 2;
        final int halfWidth = width / 2;

        while ((halfheight / inSampleSize) >= reqHeight
                && (halfWidth / inSampleSize) >= reqWidth) {
            inSampleSize *= 2;
        }
    }

    return inSampleSize;
}

这里两个代码执行图像调整大小但不同的方式,所以我如何识别哪一个是好的和简单的.

解决方法

缩放:首先,您在内存中解码整个位图,然后进行缩放.

采样:您可以获得所需的缩放位图,而无需在内存中加载整个位图.

Android上Google地图的缩放事件

Android上Google地图的缩放事件

我们正在构建一个使用google maps api的应用程序。

我有MapController和MapView,并使用以下命令启用了内置的缩放控件:

mapView.setBuiltInZoomControls(true);

我现在想在用户实际放大地图时得到一个事件,我该如何处理?我找不到能检测到缩放级别变化的此类事件或任何常规事件。

更新资料

mapView.getZoomControls()已弃用。并且文档建议改用mapView.setBuiltInZoomControls(bool)。没关系,但是我根本无法弄清楚如何对内置缩放控件中的事件采取行动。

Android上如何实现雷达图的缩放动画

Android上如何实现雷达图的缩放动画

如何在Android上如何根据雷达图动态获取的数据,实现上面的动态缩放动画?

已经实现了绘制雷达图,并且根据到来的数据动态展示雷达图,但是无法两组数据之间变化的动态效果(如上图所示)

有什么Android的库可以用吗?

 

baidu 地图 api 多个标签 在同一视野内显示 自动配置合适的缩放等级

baidu 地图 api 多个标签 在同一视野内显示 自动配置合适的缩放等级

setViewport  函数 
//初始化
var myMap = new BMap.Map("container");
myMap.addControl(new BMap.NavigationControl());
myMap.enableScrollWheelZoom();    //启用滚轮放大缩小,默认禁用
myMap.enableContinuousZoom(); 
 
    var gspinfo = <?php  echo json_encode($map_info);?>; //将php数组通过json方式传给js
    
    //可以转化gps坐标
 
    myMap.centerAndZoom(new BMap.Point(lat_point, lng_point), leva); 
    var mapWforGPS = new BMapLib.MapWrapper(myMap, BMapLib.COORD_TYPE_GPS);  
    //================================
function ComplexCustomOverlay(point, text, mouseoverText){
      this._point = point;
      this._text = text;
      this._overText = mouseoverText;
    }
    ComplexCustomOverlay.prototype = new BMap.Overlay();
    ComplexCustomOverlay.prototype.initialize = function(map){
      this._map = map;
      var divm = this._div = document.createElement("div");
      divm.style.position = "absolute";
      divm.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
      divm.style.backgroundColor = "#EE5D5B";
      divm.style.border = "1px solid #BC3B3A";
      divm.style.color = "white";
      divm.style.height = "18px";
      divm.style.padding = "2px";
      divm.style.lineHeight = "18px";
      divm.style.whiteSpace = "nowrap";
      divm.style.MozUserSelect = "none";
      divm.style.fontSize = "12px"
      var span = this._span = document.createElement("span");
      divm.appendChild(span);
      span.appendChild(document.createTextNode(this._text));      
      var that = this;
      var arrow = this._arrow = document.createElement("div");
      arrow.style.background = "url(http://map.baidu.com/fwmap/upload/r/map/fwmap/static/house/images/label.png) no-repeat";
      arrow.style.position = "absolute";
      arrow.style.width = "11px";
      arrow.style.height = "10px";
      arrow.style.top = "22px";
      arrow.style.left = "10px";
      arrow.style.overflow = "hidden";
      divm.appendChild(arrow);
     
      divm.onmouseover = function(){
        this.style.backgroundColor = "#6BADCA";
        this.style.borderColor = "#0000ff";
        this.getElementsByTagName("span")[0].innerHTML = that._overText;
        arrow.style.backgroundPosition = "0px -20px";
      }
      divm.onmouseout = function(){
        this.style.backgroundColor = "#EE5D5B";
        this.style.borderColor = "#BC3B3A";
        this.getElementsByTagName("span")[0].innerHTML = that._text;
        arrow.style.backgroundPosition = "0px 0px";
      }
      myMap.getPanes().labelPane.appendChild(divm);
      
      return divm;
    }
    ComplexCustomOverlay.prototype.draw = function(){
      var map = this._map;
      var pixel = map.pointToOverlayPixel(this._point);
      this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
      this._div.style.top  = pixel.y - 30 + "px";
    }
    //==============================
      
       points = Array();
    for (var i = 0; i < gl_; i++) {
        //添加gps坐标mkr
        //var gpsMkr = new BMap.Marker(new BMap.Point(/*GPS坐标*/gspinfo[i].lat ,gspinfo[i].lng));
        
        //myMap.centerAndZoom(gpsMkr, leva); 
        
        //mapWforGPS.addOverlay(gpsMkr);  
        // var marker = new BMap.Marker(gpsMkr); 
        //var labelgps = new BMap.Label(gspinfo[i].drugname,{offset:new BMap.Size(20,-10)});
        
        //gpsMkr.setLabel(labelgps);
          points[i]= new BMap.Point(gspinfo[i].lat,gspinfo[i].lng);
        //===========================
          var txt = gspinfo[i].drugname, mouseoverTxt =gspinfo[i].asi+'' ''+txt;
            //添加自定义标签              
          var myCompOverlay = new ComplexCustomOverlay(new BMap.Point(gspinfo[i].lat,gspinfo[i].lng)," "+gspinfo[i].asi+" ",mouseoverTxt);
          myMap.addOverlay(myCompOverlay);
          //points[$i]=new BMap.Point(gspinfo[i].lat,gspinfo[i].lng);
        } 
        myMap.setViewport(points); //调用setViewport 设置视野
//points = [new BMap.Point(gspinfo[i].lat,gspinfo[i].lng),new BMap.Point(gspinfo[i].lat,gspinfo[i].lng),new BMap.Point(gspinfo[i].lat,gspinfo[i].lng) ]
/////////////////


关于iphone – 将MapKit地图的缩放/边界与RouteMe地图的缩放/边界相匹配地图边缘调整的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于android – 位图的缩放和采样有什么区别?、Android上Google地图的缩放事件、Android上如何实现雷达图的缩放动画、baidu 地图 api 多个标签 在同一视野内显示 自动配置合适的缩放等级等相关内容,可以在本站寻找。

本文标签: