Javascript objectliteral位置是类型的实例?

Javascript objectliteral位置是类型的实例?,javascript,dom,google-maps-api-3,javascript-objects,prototypal-inheritance,Javascript,Dom,Google Maps Api 3,Javascript Objects,Prototypal Inheritance,在下面的可视化中 对象文字geolocation位于navigator(即navigator.geolocation)的上下文中,但根据以下代码 <script src="http://maps.googleapis.com/maps/api/js" type="text/javascript"> </script> <script type="text/javascript">

在下面的可视化中

对象文字
geolocation
位于
navigator
(即
navigator.geolocation
)的上下文中,但根据以下代码

<script src="http://maps.googleapis.com/maps/api/js" type="text/javascript">
            </script>
            <script  type="text/javascript">
                    function showLocation(){
                        if(navigator.geolocation){
                            navigator.geolocation.getCurrentPosition(showPosition);
                        }else{
                            alert('geo location is not supported');
                        }
                    }

                    function showPosition(position){
                        console.log(Object.prototype.toString.call(position));
                        var mapProp = {
                            center: new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
                            zoom: 5,
                            mapTypeId: google.maps.MapTypeId.ROADMAP
                          };                
                        new google.maps.Map(document.getElementById("googleMap"), mapProp);
                    }
            </script>

函数showLocation(){
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(showPosition);
}否则{
警报(“不支持地理位置”);
}
}
功能显示位置(位置){
log(Object.prototype.toString.call(position));
var mapProp={
中心:新的google.maps.LatLng(position.coords.latitude,position.coords.longitude),
缩放:5,
mapTypeId:google.maps.mapTypeId.ROADMAP
};                
新的google.maps.Map(document.getElementById(“谷歌地图”),mapProp);
}

单击下面以获取您的地理位置

点击

在调试过程中,
position
是类型
position
的一个实例,如下所示

我在
navigator
和googleapi中都看不到
Position

1)
位置
(大写p)的上下文是什么?它是函数构造函数还是对象文本


2)
位置中的成员列表(如
coords
)是什么?

看起来您可能将google api与内置在浏览器中的navigator api混淆了。传递到
showPosition
函数中的position参数不是来自google,因此不在google api规范中。请回答您的问题:

1)
position
not
position
是地理位置构造函数的一个实例,使其成为一个对象

2)
position
有以下成员:
coords
&
timestamp
timestamp
是一个以毫秒为单位表示当前时间的数字
coords
本身就是一个对象(坐标构造函数的实例),它有自己的成员如下:
精度
高度
高度准确度
航向
纬度
经度
,以及
速度


希望这有帮助

但是
Object.prototype.toString.call(position)
表示
[Object position]
。调试器也这么说。这很奇怪,因为在我的浏览器和JSFIDLE中执行相同的操作会返回不同的结果:您无法找到api,因为您在寻找错误的东西。在Mozilla中,它被称为
位置
,在webkit中,它被称为
地理位置
。但还是一样。输入参数是这两个构造函数的实例,但它仍然具有上面列出的相同成员。基本上,正如我前面所说的,您将google api与navigator api混淆了。因此,你无法找到你正在寻找的东西。所以,为了明确回答你的问题,Position(大写p)是一个函数构造函数,Position(小写)是该函数的一个实例。我知道
Date
是一个函数构造函数,我也知道它是
window.Date
。你现在能回答吗?那么,你的问题是,如何从全局范围访问
位置
构造函数?如果是这样的话,不。。。。没有
窗口。位置
<代码>位置
是navigator地理定位api的私有成员。当您调用浏览器时,会动态地为您构造一个对象文本,并将其传递到您提供的函数中。如果要访问构造函数本身,可以通过
position.constructor
访问构造函数并将其应用于所选变量,将其保存到全局变量中。
<p> Click below to get your geo location</p>
        <button onclick="showLocation();">Click</button>
        <div id="googleMap" style="width:500px;height:380px;border: 1px solid red;"></div>