title: Geolocation - can't get latitude and longitude in React/Redux app
body: <p>I have following action creator:</p>
  
  <pre><code>export const getLocation = () =&gt; {
      const geolocation = navigator.geolocation;
  
      const location = new Promise((resolve, reject) =&gt; {
          if (!geolocation) {
              reject(new Error('Not Supported'));
          }
  
      geolocation.getCurrentPosition((position) =&gt; {
          resolve(position);
      }, () =&gt; {
          reject (new Error('Permission denied'));
      });
    });
  
    return {
        type: GET_LOCATION,
        payload: location
    }
  };
  </code></pre>
  
  <p>And following reducer for <code>GET_LOCATION</code> type:</p>
  
  <pre><code>case GET_LOCATION: {
            return {
                ...state,
                location: {
                    latitude: action.location.coords.latitude,
                    longitude: action.location.coords.latitude,
  
                }
            }
        }
  </code></pre>
  
  <p>I try to use this data in my component like so:</p>
  
  <pre><code>import React, { Component } from 'react';
  import { connect } from 'react-redux';
  import { getLocation } from '../actions';
  import { bindActionCreators } from 'redux';
  
  class UserLocation extends Component {
       constructor(props) {
           super(props);
       }
  
       componentWillMount() {
           this.props.getLocation();
       }
  
       render() {
           return (
              &lt;div&gt;
                  &lt;div&gt;&lt;span&gt;latitude:&lt;/span&gt;{this.props.location.latitude} 
              &lt;/div&gt;
              &lt;div&gt;&lt;span&gt;longitude:&lt;/span&gt;{this.props.location.longitude} &lt;/div&gt;
          &lt;/div&gt;
      );
    }
  }
  
  const mapDispatchToProps = dispatch =&gt; {
      return bindActionCreators( { getLocation }, dispatch )
  }
  
  export default connect(null, mapDispatchToProps)(UserLocation);
  </code></pre>
  
  <p>But everytime when I load this component I get <code>TypeError: Cannot read property 'latitude' of undefined</code></p>
  
  <p>Can you please point me where I was wrong?</p>