10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ReactNative(Expo)でMapを利用する

Last updated at Posted at 2019-09-16

準備

npm install --save react-native-maps

イメージ

スクリーンショット 2019-09-16 19.34.44.png

実装

地図を表示してピン(Marker)を設置。クリックできるようにする。

App.js
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import MapView from 'react-native-maps';

export default class App extends React.Component {
    render() {
        return (
            <MapView
                style={{ flex: 1 }}
                initialRegion={{
                    latitude: 35.681236,
                    longitude: 139.767125,
                    latitudeDelta: 0.02, //小さくなるほどズーム
                    longitudeDelta: 0.02,
                }}
            >
                <MapView.Marker
                    coordinate={{
                        latitude: 35.681236,
                        longitude: 139.767125,
                    }}
                    title={"東京駅"}
                    description={"JRの駅です。"}
                    onPress={()=>alert("click")}
                />
            </MapView>
        );
    }
}

注意点

AndroidではGoogle Map APIのKeyの設定が必要らしい(iOSもかな)。

まとめると下記のような感じかな。。。

app.json

{
  "expo": {

  },
  "ios": {
    "config": {
      "googleMapsApiKey": "[API_Key]"
    }
  },
  "android":{
  		"config":{
  			"googleMaps":{
  				"apiKey": "[API_KEY]"
  			}
  		}
  }
}
10
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?