Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { Platform, StyleSheet, Text, View } from 'react-native';
  3. import MapView from 'react-native-maps';
  4. import Axios from 'axios';
  5.  
  6.  
  7. export default class App extends Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. address:'',
  12. latitude:'',
  13. longitude:'',
  14. markers:[],
  15. }
  16. }
  17.  
  18.  
  19. // componentDidMount() {
  20. // console.log(this.state.latitude);
  21. // Axios({
  22. // method: 'get',
  23. // url: 'http://202.51.125.114/location/public/api/locations',
  24. // dataType: 'json',
  25. // headers: {
  26. // 'Accept': 'application/json',
  27. // 'Content-Type': 'application/json',
  28. // },
  29. // })
  30. // .then(response => {
  31. // console.log(response.data);
  32. // this.setState({
  33. // markers: response.data.results.locations,
  34. // })
  35. // console.log(this.state.markers);
  36. // })
  37. // .catch((error) => {
  38. // console.error(error);
  39. // });
  40.  
  41. // }
  42.  
  43.  
  44. // componentDidMount(){
  45. // this.makeRemoteRequest();
  46. // }
  47. // makeRemoteRequest = () => {
  48.  
  49. // // api profile
  50. // const url = 'http://202.51.125.114/location/public/api/locations'
  51. // headers = {
  52. // 'Accept': 'application/json',
  53. // 'Content-Type': 'application/json',
  54. // }
  55. // fetch(url, headers, {method:'GET'})
  56. // .then(data=>data.json())
  57. // .then(res=> {
  58. // console.log(res.results.marker);
  59. // // dari selesai fetching api profile
  60. // this.setState({
  61. // marker: res.results.locations,
  62. // })
  63. // console.log(this.state.marker);
  64. // })
  65. // .catch(err=>console.warn({err}))
  66. // }
  67.  
  68.  
  69. render() {
  70. this.state = {
  71. markers: [{
  72. title: 'hi',
  73. coordinates: {
  74. latitude: 3.148561,
  75. longitude: 101.652778
  76. },
  77. },
  78. {
  79. title: 'hello',
  80. coordinates: {
  81. latitude: 3.149771,
  82. longitude: 101.655449
  83. },
  84.  
  85. },
  86. {
  87. title: 'jsa',
  88. coordinates: {
  89. latitude: -6.303709,
  90. longitude: 106.5857977
  91. },
  92.  
  93. },
  94. {
  95. title: 'jsa_HO',
  96. coordinates: {
  97. latitude: -6.1675273,
  98. longitude: 106.8208337
  99. },
  100.  
  101. },
  102.  
  103.  
  104. ]
  105. }
  106. return (
  107.  
  108. <MapView
  109. style={{ flex: 1 }}
  110. showsUserLocation={true}
  111. >
  112. {this.state.markers.map((marker, index) => (
  113. <MapView.Marker key={index}
  114. coordinate={marker.coordinates}
  115. title={marker.title}
  116. />
  117. ))}
  118. </MapView>
  119. );
  120. }
  121. }
  122.  
  123. const styles = StyleSheet.create({
  124. container: {
  125. flex: 1,
  126. justifyContent: 'center',
  127. alignItems: 'center',
  128. backgroundColor: '#F5FCFF',
  129. },
  130. welcome: {
  131. fontSize: 20,
  132. textAlign: 'center',
  133. margin: 10,
  134. },
  135. instructions: {
  136. textAlign: 'center',
  137. color: '#333333',
  138. marginBottom: 5,
  139. },
  140. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement