未定义不是一个函数,谷歌地理定位
Undefined is not a function, Google Geolocation
我正试图在页面中的谷歌地图元素上显示一个地址作为标记。
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=my_key&sensor=true&callback=initialize"></script>
<script language="javascript" type="text/javascript">
navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
var latitude;
var longitude;
var map;
function foundLocation(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
}
function noLocation() {
//Do something here in the case that no location is found, or user denies access
}
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(latitude, longitude),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
//setMarkers();
}
function addMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
markersArray.push(marker);
}
</script>
<span id="ctl00_ContentPlaceHolder1_lblGeneratedScript"><script language="javascript" type="text/javascript">
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': "123 Test Dr."}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
addMarker(results[0].geometry.location);
} else {
alert("Geocode failed! Reason: " + status);
}
});
</script>
</span>
但是,在这条线上
var geocoder = new google.maps.Geocoder();
我得到一个未捕获类型的错误"未定义不是一个函数。"
在我的代码选择中,我省略了api键,并更改了用于测试的地址。(我的家庭地址)
此外,我正在使用ASP.NET在span标记中生成脚本。
在API完成加载之前,不能构造Geocoder对象。在initialize
方法中或之后调用它。
相关文章:
- JavaScript函数未返回谷歌地图lat/long的值
- .scroll()函数在上次更新后在谷歌chrome中定位闪烁
- 谷歌地图:函数返回未定义的值在console.log中运行良好
- 谷歌地图v3:当函数'失败'呼叫
- 如何使用图表包装函数有条件地格式化谷歌可视化表单元格
- 使用谷歌地图:一个返回undefined的自定义javascript函数
- 为什么谷歌应用程序的电子表格setValue函数没有在单元格中设置值
- 谷歌扩展:如何在弹出窗口中按下按钮时在我的javascript文件中运行函数
- 对谷歌地图v3 API getDetails()函数感到困惑
- 谷歌地图 - 从未定义的函数返回getPosition
- 访问谷歌登录函数 Angular 2 中的构造函数参数
- 谷歌应用程序脚本-正在尝试使用getUrl.TypeError:在对象工作表中找不到函数getUrl
- 未定义不是一个函数,谷歌地理定位
- 谷歌地图API没有;t显示地图,如果中心由javascript函数填充
- 谷歌地图API多段线创建失败;未捕获类型错误:数字不是函数;
- 这一点.setValues不是一个函数谷歌地图API 3
- 调用Javascript函数谷歌地图
- 使用变量在下一个函数(谷歌表查询)
- jshint-Don't在循环中生成函数-谷歌地图
- "未找到脚本函数"-谷歌应用程序脚本