Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 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. // //ip public
  24. // url: 'http://202.51.125.114/location/public/api/locations',
  25. // dataType: 'json',
  26. // headers: {
  27. // 'Accept': 'application/json',
  28. // 'Content-Type': 'application/json',
  29. // },
  30. // })
  31. // .then(response => {
  32. // console.log(response.data);
  33. // this.setState({
  34. // markers: response.data.results.locations,
  35. // })
  36. // console.log(this.state.markers);
  37. // })
  38. // .catch((error) => {
  39. // console.error(error);
  40. // });
  41.  
  42. // }
  43.  
  44. // componentDidMount() {
  45. // console.log(this.state.latitude);
  46. // Axios({
  47. // method: 'get',
  48. // //ip leptop
  49. // url: 'http://192.268.6.13/location/public/api/locations',
  50. // dataType: 'json',
  51. // headers: {
  52. // 'Accept': 'application/json',
  53. // 'Content-Type': 'application/json',
  54. // },
  55. // })
  56. // .then(response => {
  57. // console.log(response.data);
  58. // this.setState({
  59. // markers: response.data.results.locations,
  60. // })
  61. // console.log(this.state.markers);
  62. // })
  63. // .catch((error) => {
  64. // console.error(error);
  65. // });
  66.  
  67. // }
  68.  
  69. // componentDidMount() {
  70. // console.log(this.state.latitude);
  71. // Axios({
  72. // method: 'get',
  73. // //local
  74. // url: 'http://localhost:8000/api/locations',
  75. // dataType: 'json',
  76. // headers: {
  77. // 'Accept': 'application/json',
  78. // 'Content-Type': 'application/json',
  79. // },
  80. // })
  81. // .then(response => {
  82. // console.log(response.data);
  83. // this.setState({
  84. // markers: response.data.results.locations,
  85. // })
  86. // console.log(this.state.markers);
  87. // })
  88. // .catch((error) => {
  89. // console.error(error);
  90. // });
  91.  
  92. // }
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. render() {
  101. this.state = {
  102. markers: [{
  103. title: 'hi',
  104. coordinates: {
  105. latitude: 3.148561,
  106. longitude: 101.652778
  107. },
  108. },
  109. {
  110. title: 'hello',
  111. coordinates: {
  112. latitude: 3.149771,
  113. longitude: 101.655449
  114. },
  115.  
  116. },
  117. {
  118. title: 'jsa',
  119. coordinates: {
  120. latitude: -6.303709,
  121. longitude: 106.5857977
  122. },
  123.  
  124. },
  125. {
  126. title: 'jsa_HO',
  127. coordinates: {
  128. latitude: -6.1675273,
  129. longitude: 106.8208337
  130. },
  131.  
  132. },
  133.  
  134.  
  135. ]
  136. }
  137. return (
  138.  
  139. <MapView
  140. style={{ flex: 1 }}
  141. showsUserLocation={true}
  142. >
  143. {this.state.markers.map((marker, index) => (
  144. <MapView.Marker key={index}
  145. coordinate={marker.coordinates}
  146. title={marker.title}
  147. />
  148. ))}
  149. </MapView>
  150. );
  151. }
  152. }
  153.  
  154. const styles = StyleSheet.create({
  155. container: {
  156. flex: 1,
  157. justifyContent: 'center',
  158. alignItems: 'center',
  159. backgroundColor: '#F5FCFF',
  160. },
  161. welcome: {
  162. fontSize: 20,
  163. textAlign: 'center',
  164. margin: 10,
  165. },
  166. instructions: {
  167. textAlign: 'center',
  168. color: '#333333',
  169. marginBottom: 5,
  170. },
  171. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement