This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getPredictionWithDetail(searchQuery, key) { | |
return getPredictionList(searchQuery, key) | |
.then(result => { | |
const predictions = result.predictions; | |
const predictionsPromise = predictions.map(prediction => | |
getPlaceDetails(prediction.place_id, key) | |
); | |
return Promise.all(predictionsPromise); | |
}) | |
.then(data => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
EDIT!! request-promise mengalami error saat akan digunakan dengan react-native, | |
maka kita akan menggunakan native fetch dengan bantuan qs (queryString) module. | |
untuk install gunakan `npm install --save qs` | |
*/ | |
const qs = require('qs'); | |
function getPredictionList(searchQuery, key) { | |
const queryString = qs.stringify({ | |
input: searchQuery, | |
type: 'geocode', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { TextInput, StyleSheet } from 'react-native'; | |
const styles = StyleSheet.create({ | |
AutoCompleteBox: { | |
marginHorizontal: 20, | |
padding: 10, | |
alignSelf: 'stretch', | |
backgroundColor: '#FFF', | |
borderColor: '#BBB', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { | |
TextInput, | |
View, | |
Text, | |
StyleSheet, | |
TouchableOpacity | |
} from 'react-native'; | |
const styles = StyleSheet.create({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rest of code same as before.. | |
const AutoCompleteBox = props => ( | |
<View style={styles.AutoCompleteBox}> | |
<TextInput | |
{...props} | |
underlineColorAndroid="#FFF" | |
style={styles.AutoCompleteInput} | |
/> | |
<TouchableOpacity onPress={() => props.clearInput()}> | |
<Text style={styles.AutoCompleteClose}>X</Text> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { View, Text, FlatList, StyleSheet } from 'react-native'; | |
const styles = StyleSheet.create({ | |
AutoCompleteResultList: { | |
marginHorizontal: 22, | |
borderWidth: 2, | |
borderColor: '#aaa', | |
borderBottomLeftRadius: 10, | |
borderBottomRightRadius: 10, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { StyleSheet, Text, View } from 'react-native'; | |
import AutoCompleteBox from '../components/AutoCompleteBox'; | |
import AutoCompleteResultList from '../components/AutoCompleteResultList'; | |
class SearchPage extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
query: '', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { StyleSheet, Text, View } from 'react-native'; | |
import AutoCompleteBox from '../components/AutoCompleteBox'; | |
import AutoCompleteResultList from '../components/AutoCompleteResultList'; | |
import { getPredictionWithDetail } from '../services.js'; | |
const KEY = 'Your_API_KEY'; | |
class SearchPage extends Component { | |
constructor(props) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const qs = require('qs'); | |
// import cancelable-fetch | |
const fetch = require('react-native-cancelable-fetch'); | |
function getPredictionList(searchQuery, key) { | |
const queryString = qs.stringify({ | |
input: searchQuery, | |
type: 'geocode', | |
key | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//..rest of the code still the same | |
class AutoCompleteResultList extends Component { | |
renderItem({ item }) { | |
return ( | |
<View style={styles.AutoCompleteResultItem}> | |
<Text style={styles.titleText}>{item.name}</Text> | |
<Text style={styles.text}>{item.formatted_address}</Text> | |
</View> | |
); | |
} |