Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- import { Platform, StyleSheet, Text, View } from 'react-native';
- import MapView from 'react-native-maps';
- import Axios from 'axios';
- export default class App extends Component {
- constructor(props) {
- super(props);
- this.state = {
- address:'',
- latitude:'',
- longitude:'',
- markers:[],
- }
- }
- // componentDidMount() {
- // console.log(this.state.latitude);
- // Axios({
- // method: 'get',
- // url: 'http://202.51.125.114/location/public/api/locations',
- // dataType: 'json',
- // headers: {
- // 'Accept': 'application/json',
- // 'Content-Type': 'application/json',
- // },
- // })
- // .then(response => {
- // console.log(response.data);
- // this.setState({
- // markers: response.data.results.locations,
- // })
- // console.log(this.state.markers);
- // })
- // .catch((error) => {
- // console.error(error);
- // });
- // }
- // componentDidMount(){
- // this.makeRemoteRequest();
- // }
- // makeRemoteRequest = () => {
- // // api profile
- // const url = 'http://202.51.125.114/location/public/api/locations'
- // headers = {
- // 'Accept': 'application/json',
- // 'Content-Type': 'application/json',
- // }
- // fetch(url, headers, {method:'GET'})
- // .then(data=>data.json())
- // .then(res=> {
- // console.log(res.results.marker);
- // // dari selesai fetching api profile
- // this.setState({
- // marker: res.results.locations,
- // })
- // console.log(this.state.marker);
- // })
- // .catch(err=>console.warn({err}))
- // }
- render() {
- this.state = {
- markers: [{
- title: 'hi',
- coordinates: {
- latitude: 3.148561,
- longitude: 101.652778
- },
- },
- {
- title: 'hello',
- coordinates: {
- latitude: 3.149771,
- longitude: 101.655449
- },
- },
- {
- title: 'jsa',
- coordinates: {
- latitude: -6.303709,
- longitude: 106.5857977
- },
- },
- {
- title: 'jsa_HO',
- coordinates: {
- latitude: -6.1675273,
- longitude: 106.8208337
- },
- },
- ]
- }
- return (
- <MapView
- style={{ flex: 1 }}
- showsUserLocation={true}
- >
- {this.state.markers.map((marker, index) => (
- <MapView.Marker key={index}
- coordinate={marker.coordinates}
- title={marker.title}
- />
- ))}
- </MapView>
- );
- }
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- backgroundColor: '#F5FCFF',
- },
- welcome: {
- fontSize: 20,
- textAlign: 'center',
- margin: 10,
- },
- instructions: {
- textAlign: 'center',
- color: '#333333',
- marginBottom: 5,
- },
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement