Guest User

Untitled

a guest
Oct 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. const GettingStartedGoogleMap = withGoogleMap(props =>(
  2. <GoogleMap
  3. defaultZoom={13}
  4. center={props.center}
  5. >
  6. {if(props.markers !== undefined && props.markers != null && props.markers.length > 0)
  7. {props.markers.map(marker => (
  8. <InfoWindow position={{ lat: marker.latitude, lng: marker.longitude }}
  9. key={marker.id}>
  10. <div>
  11. {marker.price}
  12. </div>
  13. </InfoWindow>
  14. ))}
  15. }
  16. </GoogleMap>
  17. ));
  18.  
  19. export class AppMap extends Component {
  20.  
  21. constructor(props) {
  22. super(props);
  23. this.Ref = firebase.database().ref().child('app').child('cards');
  24. this.state = ({
  25. markers : [{
  26. latitude: "",
  27. longitude: "",
  28. price: "",
  29. id: ""
  30. }]
  31. })
  32. }
  33.  
  34. componentWillUpdate (){
  35. const previousMarker = this.state.markers;
  36. this.Ref.orderByChild('address').equalTo(this.props.city)
  37. .on('child_added', snap => {
  38. previousMarker.push({
  39. latitude: snap.node_.children_.root_.right.left.value.children_.root_.left.value.value_,
  40. longitude: snap.node_.children_.root_.right.left.value.children_.root_.value.value_,
  41. price: snap.node_.children_.root_.value.value_,
  42. key: snap.key + "_Marker",
  43.  
  44. })
  45.  
  46. console.log(previousMarker)
  47.  
  48. })
  49. }
  50.  
  51.  
  52. render() {
  53. return (
  54. <div style={{height: `400px`}}>
  55. <GettingStartedGoogleMap
  56. containerElement={
  57. <div style={{ height: `100%` }} />
  58. }
  59. mapElement={
  60. <div style={{ height: `100%` }} />
  61. }
  62.  
  63. center={this.props.center}
  64. markers={this.state.markers}
  65.  
  66. googleMapURL="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places"
  67. />
  68. </div>
  69. );
  70. }
  71. }
Add Comment
Please, Sign In to add comment