简体   繁体   English

mapview如何自动缩放

[英]mapview how to auto zoom

Answer: set delta to a smaller decimal number, eg 0.005 答案:将增量设置为较小的十进制数,例如0.005


I am using <MapView> component, trying to make it default zoom in to a certain degree so that can see the street by default. 我正在使用<MapView>组件,尝试使其默认放大到一定程度,以便默认情况下可以看到街道。 I thought "Delta" is controlling how much we want to zoom, but i don`t see any different when i set different value. 我以为“ Delta”控制着我们要缩放多少,但是当我设置不同的值时我看不到任何不同。

any idea how can i have MapView default zoom in? 任何想法我怎么能有MapView默认放大?

    region: {
        latitude: xxxx,
        longitude: xxxx,
        latitudeDelta: 0.4,
        longitudeDelta: 0.4,
        title: "Your Address"
    }

       <MapView style={styles.map}
                 region={this.state.region}
                 showsUserLocation={true}
                 annotations={[this.state.region]}>
        </MapView>

So with Apple's MKMapView class the zoom level is controlled indirectly. 因此,使用Apple的MKMapView类可以间接控制缩放级别。 Rather than specifying how much you want to zoom on a point, you set the region you want to display. 无需指定要缩放的点数,而是设置要显示的区域。 This requires a centre point, and a span - which can use the latitude and longitude deltas to the edge of the map. 这需要一个中心点和一个跨度-可以使用纬度和经度变化量到地图的边缘。 A smaller latitude and longitude delta will mean that you are zoomed in closer to the centre, and vice versa. 较小的纬度和经度增量意味着您将放大到更靠近中心的位置,反之亦然。

Here is the documentation. 这是文档。

https://developer.apple.com/library/mac/documentation/MapKit/Reference/MapKitDataTypesReference/index.html#//apple_ref/swift/struct/c:@SA@MKCoordinateRegion https://developer.apple.com/library/mac/documentation/MapKit/Reference/MapKitDataTypesReference/index.html#//apple_ref/swift/struct/c:@SA@MKCoordinateRegion

The google maps API allows you to directly control the zoom level, but there are also libraries that will work for MKMapView. Google Maps API允许您直接控制缩放级别,但是也有一些库适用于MKMapView。

I think that MapView in React Native automatically zooms to your location. 我认为React Native中的MapView会自动缩放到您的位置。 If that is your case, and you don't want it to happen, you can comment this line in the react native file RCTMap.m in your react-native node module : _followUserLocation = showsUserLocation; 如果是这种情况,并且您不希望发生这种情况,可以在react-native节点模块的react native文件RCTMap.m中注释以下行: _followUserLocation = showsUserLocation;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM