小编Mac*_*yer的帖子

如何使用react-native-maps获取当前位置

我试图使用react-native地图在android设备上的当前用户地理位置上渲染地图。

这是到目前为止我得到的:

import React, { Component } from 'react';

import {
  View,
  StyleSheet,
  Dimensions,
} from 'react-native';

import MapView from 'react-native-maps';

const {width, height} = Dimensions.get('window')

const SCREEN_HEIGHT = height
const SCREEN_WIDTH = width
const ASPECT_RATIO = width / height
const LATITUDE_DELTA = 0.0922
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO

class MapComponent extends Component {
  constructor() {
    super()
    this.state = {
      initialPosition: {
        latitude: 0,
        longitude: 0,
        latitudeDelta: 0,
        longitudeDelta: 0,
      },
    }
  }

  componentDidMount() {
    navigator.geolocation.getCurrentPosition((position) => {
      var …
Run Code Online (Sandbox Code Playgroud)

android geolocation react-native react-native-maps

6
推荐指数
2
解决办法
1万
查看次数