Kobkrit Viriyayudhakorn, Ph.D.
CEO of iApp Technology Limited.
Thai Travel Directory App
• React Native Map Components
for iOS + Android
• Made by Airbnb
• iOS => Choose either
• Google Map
• Apple Map
• Android => Only Google Map
1. $ react-native init --version=“0.35.0” l9_map
2. $ npm install react-native-maps --save
3. $ react-native link
4. Write some code
5. $ react-native run-ios
6. For Android, we have extra steps.
Android Installation Extra
1. Google Map need an API key
2. You can get your own at https://
console.developers.google.com or using my API
3. Add the Google Map’s API key at
4. $ react-native run-android
Adding Google API key
Add meta-data tag as shown below, between <application>
tag in AndroidManifest.xml
Adding Basic Map Code
You can see full l9_map_1 source code at the end of lecture note (A4)
1. $ react-native run-ios
2. Empty screen come up!?
3. Map need the width,
height. Can not use ﬂex:1
Adding Width,Height to Map
l9_map_2Full l9_map_2 source code at the end of lecture note
• Dimensions return current screen’s
width and height.
• Thus, the map will be full screen.
1. Welcome to San Francisco, the
home of tech companies in the world.
2. At the center point of the screen is
3. The zoom of the map is specify by
4. At the Equator
1 LatitudeDelta => 110.57 KM
1 LongitudeDelta => 111.32 KM
Make it controllable by State
Instead of, the ﬁxed regions, we make it as a state.
Make it controllable by State #2
• onRegionChange props will be called when the location/zoom
are changed, with the value of new location/zoom (region)
• Region props deﬁned the current location/zoom in the map.
1. Drag on map view to move
2. Once drag, this.state.region
was updated by
3. Text at the lower third of the
screen is updated according
to the this.state.region
4.Try two ﬁngers pinch, to
zoom, to rotate the map. In
simulator, press alt(option)
button to two ﬁngers pinch.
Conﬁgure the MapView
And much more..
MapEvents are also catchable
And much more..
Let conﬁgure some MapView
Let’s change the mapType
mapType=“hybrid” mapType=“satellite” mapType=“terrain”
Adding Map Markerl9_map_5
Let move the location to the Victory
Monument, Bangkok, Thailand.
coordinate => LatLng Object of that
title => Title of Information popup
description => Description of popup
1. MapView.Marker creates a red-
pin marker on the map (for Apple
map), and droplet shape pin on
Google map. Place it as children
of the MapView.
2.Touch the pin to show up the
popup windows, touch elsewhere
to hide it.
3. The map is draggable.
4.You can add many markers you
Apple Map l9_map_5
Add More Markers!
Don’t forget to add “key”
We found that there are warnings below…
It will occur every time, when we use JSX under loop.
To remove it, Add key props.
To distinguish each MapView.Marker
Adding custom images to
• Load image into state,
and display it on map
using “image” prop.
• Image shall be around
56px X 56px
Nah,.. Change my mind
I want custom view to represent
markers instead… l9_map_8
Normal Picture Group of View
Marker as Custom View
• Add View as the children of MapView.Marker
That such a boring
Popup… I want to have
a photo in it. (Custom Popup)
• Add MapView.Callout as the children of the MapView.Marker
Drawing Circle on Map
Drawing Polyline on Map
Drawing Polygon on Map
Drawing Something on Map
Travel Directory App
• Center map at the Victory
• Map can be moved.
• Tap on icon, show Title and
• Push buttons to move the map
to that speciﬁc location and
zoom in and open the call out.
• Starting to modify the app from
method change the
state of region to
assigned latlng, and
zoom in by setting
The Change is so sudden!
• I want to make it smoothly animate to the new location!
• MapView have a method for that called “animateToRegion”
• They accept 2 arguments, i.e., Region to move to, and, How long
does the animation will need (in ms).
How to reference to the
• How we can reference to our UI in react?
• Luckily, we have Ref System!
• We can have ref props in any component, e.g.,
<MapView ref=“map” … >
• We can reference to the MapView Component by
• We move to the new location as speciﬁed in latlng.
• And zoom in,
• smoothly in 3 seconds (3000 ms)
Smoothly Move Map
HW: How to automatically open
call out when pressing a button?
• There is a method call “showCallout()” in MapView.Marker
• Use Ref!
• This is your homework!