代码之家  ›  专栏  ›  技术社区  ›  Mahdi Bashirpour

在react native中从viewport获取latitudedelta和longitudedelta

  •  0
  • Mahdi Bashirpour  · 技术社区  · 6 年前

    我有这些数据,我想 latitudeDelta/longitudeDelta

    geometry:{
        location:{
            lat:35.7212504,
            lng:51.36276979999999
        },
        viewport:{
            northeast:{lat: 35.7290254, lng: 51.380868},
            southwest:{lat: 35.7004529, lng: 51.3492823},
        }
    }
    

    我会得到 纬度/经度 用这些数据 当然,我会说我用 react-native-google-places-autocomplete 这些数据被输出

    1 回复  |  直到 6 年前
        1
  •  1
  •   Mahdi Bashirpour    6 年前
    const { width, height } = Dimensions.get('window');
    
    const ASPECT_RATIO = width / height;
    const LATITUDE_DELTA = 0.0922;
    
    const lat = details.geometry.location.lat;
    const lng = details.geometry.location.lng;
    const latDelta = details.geometry.viewport.northeast.lat - details.geometry.viewport.southwest.lat;
    const lngDelta = latDelta * ASPECT_RATIO;
    
    let coordinate = {
        latitude: lat,
        longitude: lng,
        latitudeDelta: latDelta,
        longitudeDelta: lngDelta
    };