我正在开发一个呈现谷歌 Map API的ReactJs webapp . 但是当我的应用程序启动时应显示用户位置 . 如果设置lat和lng,则应该获得用户地理位置(纬度和经度) . 还有Gmaps的另一个功能,我只需要设置currentAddress,mapCoordinates(lat,lng)和用户位置 .

var App = React.createClass({



getInitialState(){


    GMaps.geolocate({
    success: function(position) {

        //alert("Latitude: " + position.coords.latitude + 
        //"<br>Longitude: " + position.coords.longitude); //it's works


        var userLat = position.coords.latitude;
        var userLng = position.coords.longitude;    

    },
    error: function(error) {
        alert('Geolocation failed: '+error.message);
    },
    not_supported: function() {
        alert("Your browser does not support geolocation");
    },
    always: function() {
        //alert("Done!");
    },

    });

    return {

        mapCoordinates: {

            //lat: userLat, //how to get userLat 
            //lng: userLng //how to get userLng

        }                           

    }


},

...