使用JavaScript加载多个地图库 [英] Loading multiple maps libraries with javascript

查看:98
本文介绍了使用JavaScript加载多个地图库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加载地图库和JavaScript库,以便我可以将地图嵌入到我的页面中,使用google.maps.geometry.spherical函数和地点搜索请求,但我无法加载所有3个图书馆。
目前我正在导入:

 < script type =text / javascriptsrc =http: //maps.google.com/maps?key=mykey\"></script> 
< script type =text / javascriptsrc =http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places>< / script>

但我得到错误:

语法错误
[Break On This Error]

... gs4d .gbmac,.gbes#gbg4#gbgs4d .gbmac {margin:34px 0 0 } .gbemi#gb#gbgs4d .gbmac,....

maps?k ... hrkDAmw(第1行)

GClientGeocoder未定义
[此错误解决]

var geocoder = new GClientGeocoder();

我要去哪里?

非常感谢。

第一个脚本没有指向一个javascript,这会尝试加载maps-homepage 作为脚本(当然这会失败)。



不需要包含多个脚本,只需使用:

 < script type =text / javascript
src =http://maps.googleapis.com/maps/api/js?libraries=geometry,places&sensor=false>

这将加载maps-API(V3)并包含地点+ geometry-libraries



https://developers.google.com/然而,正如Colin所说,这看起来像是V2代码。

$ b $



b

I am trying to load both the maps library and the places library with javascript so I can embed a map into my page, use google.maps.geometry.spherical functions and make places search requests but I'm having trouble loading all 3 libraries. At the moment I am importing:

<script type="text/javascript"src="http://maps.google.com/maps?key=mykey"></script>
<script type="text/javascript"src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>

But I get the errors:

syntax error
[Break On This Error]   

...gs4d .gbmac,.gbes#gbg4 #gbgs4d .gbmac{margin:34px 0 0}.gbemi#gb #gbgs4d .gbmac,....

maps?k...hrkDAmw (line 1)

GClientGeocoder is not defined
[Break On This Error]   

var geocoder = new GClientGeocoder();

Where am I going wrong?

Thanks a lot.

解决方案

The first script doesn't point to a javascript, this will try to load the maps-homepage as a script(of course this will fail).

There is no need to include multiple scripts, simply use:

<script type="text/javascript"
  src="http://maps.googleapis.com/maps/api/js?libraries=geometry,places&sensor=false">

This will load the maps-API(V3) and includes the places+geometry-libraries

https://developers.google.com/maps/documentation/javascript/libraries?hl=en

However, as Colin said, this looks like V2-code.

这篇关于使用JavaScript加载多个地图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆