posts - 310, comments - 6939, trackbacks - 0, articles - 3
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Google Maps API 2.0 参考文档(ZZ)

Posted on 2009-04-28 15:14 诗特林 阅读(1873) 评论(1)  编辑  收藏 所属分类: GIS

 

Google Maps API 2.0 参考文档

如果您仅仅想在您的网站上显示地图,您只需要知道这些类,类型和函数:

GMap2

GMapOptions

GInfoWindow

GInfoWindowTab

GInfoWindowOptions

GMarker

GMarkerOptions

GPolyline

GIcon

GPoint

GSize

GBounds

GLatLng

GLatLngBounds

GControl

GEvent

GventListener

GXmlHttp

GXml

GXslt

GLog

GDownloadUrl

GBrowserIsCompatible

如果您想扩展Maps API的功能,开发自己的控件、标注和地图类型,您就还要学习这些类和类型:

GMapPane

GOverlay

GControl

GControlPosition

GControlAnchor

GMapType

GMapTypeOptions

GTileLayer

GCopyrightCollection

GCopyright

GProjection

GMercatorProjection

GMap2

实例化类GMap2用来创建一幅地图,这是API之中首要的类,其他的都是辅助性的.

构造函数

构造函数

说明

GMap2(container, opts?)

在给定的HTML容器之中创建一个新的地图,通常是一个DIV元素.如果没有在opts.mapTypes之中设置可选参数地图类型,默认使用G_DEFAULT_MAP_TYPES类型.如果没有在opts.size可选参数之中设置地图的大小,则会自动使用container的地图大小.如果设置了opts.size参数,传入的container元素将会被设置到指定大小.具体查看查看 GMapOptions.

方法

配置

方法

返回值

说明

enableDragging()

启用地图的拖拽功能(默认已启用).

disableDragging()

禁用地图的拖拽功能.

draggingEnabled()

布尔值

假如地图的拖拽功能已启用,则返回true.

enableInfoWindow()

启用地图的信息浮窗功能(默认已启用).

disableInfoWindow()

禁用地图的信息浮窗功能,如果已经打开信息浮窗,则关闭信息浮窗.

infoWindowEnabled()

布尔值

假如地图的信息浮窗功能已启用,则返回true.

控件

方法

返回值

说明

addControl(control, position?)

在地图上添加指定控件,控件添加的位置在可选参数position之中指定. 如果没有指定该参数,则使用该控件本身指定的默认位置,即控件的GControl.getDefaultPosition()方法返回的位置.同一个控件实例不能向地图添加多次.

removeControl(control)

从地图上删除指定控件.如果该控件并没有被添加到地图,则不执行任何操作.

getContainer()

HTML节点

返回包含地图的DOM对象,通常给控件初始化方法GControl.initialize()来调用.

地图类型

方法

返回值

说明

getMapTypes()

GMapType数组

返回在地图已经添加的所有地图类型的数组.

getCurrentMapType()

GMapType

返回当前使用的地图类型.

setMapType(type)

使用给定的地图类型,该地图类型必须已经添加到地图,具体可参考构造函数和addMapType()方法.

addMapType(type)

给地图添加新的地图类型支持.查看GMapType来了解如何自定义地图类型.

removeMapType(type)

在地图之中删除地图类型支持,该方法将改变GMapTypeControl在地图上显示的按钮组,并触发removemaptype事件.

地图状态

方法

返回值

说明

isLoaded()

布尔值

如果地图已经被setCenter()初始化,则返回true.

getCenter()

GLatLng

返回地图中心点的地图坐标.

getBounds()

GLatLngBounds

返回地图视口范围的矩形区域的地理坐标.

getBoundsZoomLevel(bounds)

数字

返回显示指定的区域需要的最适合的地图缩放等级.该缩放等级是根据当前的地图类型计算出来的,如果还没有指定地图类型,将使用地图类型数组之中的第一项.

getSize()

GSize

返回地图视口的像素大小.

getZoom()

数字

返回当前的缩放等级.

更改地图状态

方法

返回值

说明

setCenter(center, zoom?, type?)

将地图视图切换到指定的中心点,也可以同时设置可选的地图缩放等级和地图类型.地图类型必须已经添加到地图.请参看构造函数和addMapType().该方法必须在构造地图实例之后初始化地图状态时立即执行.在地图刚刚构造的时候调用地图其他的方法都将会产生错误.

panTo(center)

设置地图的中心点到指定的坐标,如果该点已经在当前的视口之中,则地图中心会滑动到该位置.

panBy(distance)

地图滑动指定的像素距离.

panDirection(dx, dy)

以指定的方向滑动地图宽度一半的距离.+1代表右方和下方,-1代表左方和上方.

setZoom(level)

设置地图的缩放等级到给定值.

zoomIn()

缩小地图(将地图的缩放等级增加1).

zoomOut()

放大地图(将地图的缩放等级减少1).

savePosition()

保存地图当前的位置和缩放等级,以供以后通过returnToSavedPosition()方法来返回当前视图.

returnToSavedPosition()

返回到上一次通过savePosition()保存的地图视图.

checkResize()

检查地图容器(container)的大小是否已经发生变化,在地图容器DOM大小可能发生变化的时候调用该方法,以便地图能进行自动调整.

标注

方法

返回值

说明

addOverlay(overlay)

在地图上添加一个标注并触发地图的addoverlay事件.

removeOverlay(overlay)

在地图上删除指定的标注.如果该标注确实在地图上,则触发removeoverlay事件.

clearOverlays()

删除所有地图上的标注,并触发clearoverlays事件.

getPane(pane)

HTML节点

返回用来包含指定pane中对象的层.该方法被GOverlay实例的初始化方法GOverlay.initialize()来调用以便将自身添加到地图

信息浮窗

方法

返回值

说明

openInfoWindow(point, node, opts?)

在指定的地理点打开一个简单的信息浮窗.滑动地图以保证打开的信息浮窗可见.信息浮窗的内容以DOM节点的形式给定.

openInfoWindowHtml(point, html, opts?)

在指定的地理点打开一个简单的信息浮窗.滑动地图以保证打开的信息浮窗可见.信息浮窗的内容以HTML文本的形式给定.

openInfoWindowTabs(point, tabs, opts?)

在指定的地理点打开一个分标签的信息浮窗.滑动地图以保证打开的信息浮窗可见.信息浮窗的内容以DOM节点的形式给定.

openInfoWindowTabsHtml(point, tabs, opts?)

在指定的地理点打开一个分标签的信息浮窗.滑动地图以保证打开的信息浮窗可见.信息浮窗的内容以HTML文本的形式给定.

showMapBlowup(point, opts?)

在指定的地理点打开一个显示指定点更近的视图的信息浮窗.

closeInfoWindow()

关闭当前打开的信息浮窗.

getInfoWindow()

GInfoWindow

返回地图的信息浮窗对象.如果当前并不存在信息浮窗,则创建一个信息浮窗而不显示它.这个操作并不被enableInfoWindow()影响.

坐标转换

方法

返回值

说明

fromLatLngToDivPixel(latlng)

GPoint

计算给定的地理坐标点相对于包含地图标注和图片的层的像素相对坐标.您在给一个自定义标注定位的时候需要在GOverlay.redraw()方法之中用到该方法.

fromDivPixelToLatLng(pixel)

GLatLng

根据相对于包含地图标注和图片的层的像素相对坐标计算地理坐标.您在实现和您的标注交互的事后可能需要该方法.

fromContainerPixelToLatLng(pixel)

GLatLng

根据相对于包含整个地图的容器container DOM元素的像素相对坐标来计算地理经纬度坐标.您在和您的自定义标注进行交互的时候可能需要该方法.

事件

事件

参数

说明

addmaptype

type

在为地图添加新的地图类型的时候触发该事件.

removemaptype

type

在从地图之中删除地图类型时触发该事件.

click

overlay, point

当地图被鼠标点击的时候触发,如果鼠标点击在一个标记上,该标记就会作为第1个参数overlay传递给事件处理器,同时也会在该标记上触发click事件.否则,将只会在point参数之中传递被点击点的地理经纬度坐标.

movestart

当地图视图开始改变时触发,可能的情况有拖动(在这种情况下同时也会触发dragstart事件),或者地图的改变地图视图的方法被调用.

move

在地图被移动的时候持续触发.

moveend

在地图视图的更改完成后触发.

zoomend

oldLevel, newLevel

在地图完成缩放等级变化的时候触发,时间处理句柄将接收到之前的缩放等级和当前的缩放等级2个参数.

maptypechanged

在地图类型变化时触发.

infowindowopen

在信息浮窗打开时触发.

infowindowclose

在信息浮窗关闭时触发,假如当前的信息浮窗被openInfoWindow*()方法更改到一个新的位置,也会先触发infowindowclose事件.

addoverlay

overlay

在一个标注被addOverlay()添加到地图上之后触发,新添加的标注将会作为overlay参数被传递给信息处理句柄.

removeoverlay

overlay

在一个标注被removeOverlay()方法从地图上删除时触发,该标注将会作为overlay参数被传递给信息处理句柄.

clearoverlays

在使用clearOverlays()清除地图上所有标注时触发.

mouseover

latlng

当鼠标移动到地图之上时触发.

mouseout

latlng

当鼠标移出地图时触发.

mousemove

latlng

当鼠标在地图上移动时触发.

dragstart

当用户开始拖动地图时触发.

drag

当用户拖动地图时持续触发.

dragend

当用户停止拖动地图时触发.

GMapOptions

本类是GMap2构造函数的一个可选参数集合类,没有构造函数,直接通过object构造.

属性

属性

类型

说明

size

GSize

设置地图的像素大小,传递给地图构造函数的container(容器)将会被调整到指定大小,默认值为该container的大小.

mapTypes

GMapType数组

供使用的地图类型数组.默认为G_DEFAULT_MAP_TYPES数组.您可以改变这个预定义的地图类型数组,或者传递另一组地图类型.请参看GMap2.addMapType().

枚举 GMapPane

这些常量定义了标注在地图上显示的层次系统.分别用来显示图标、阴影、信息浮窗、信息浮窗阴影和透明的鼠标事件捕获对象.

在您为了自定义标注而继承GOverlay的时候要用到此枚举.

常量

常量

说明

G_MAP_MAP_PANE

本层显示在标记阴影的下方,直接靠着下面的地图图片层,用来放置类似折线的标记.

G_MAP_MARKER_SHADOW_PANE

本层包含标记的阴影,显示在标记的下一层.

G_MAP_MARKER_PANE

本层用来包含标记.

G_MAP_FLOAT_SHADOW_PANE

本层包含信息浮窗的阴影图片,在G_MAP_MARKER_PANE之上,以便标记能够半透明的显示在信息浮窗的阴影之中.

G_MAP_MARKER_MOUSE_TARGET_PANE

本层包含标记所使用的用来捕获用户点击的透明元素.它在G_MAP_FLOAT_SHADOW_PANE之上,所以在信息浮窗阴影下的标记依然是可点的.

G_MAP_FLOAT_PANE

本层用来包含信息浮窗,在所有层的最上方.

GKeyboardHandler

初始化本类可以为指定的地图添加键盘操作支持.相应的键和Google Maps网站上使用的相同.

(↑)、下(↓)、左(←)右按下分别代表向相应的方向持续滑动地图.其中的2个键组合则能向相应的角滑动,page down, page up, home, end四个键每次点击分别能在一个方向滑动3/4个地图的大小,这和GLargeMapControlGSmallMapControl之中的箭头按钮的功能是一样的.+,-按钮分别代表增加或者减少一个缩放等级.

构造函数

构造函数

说明

GKeyboardHandler(map)

为参数值中指定的地图启用键盘事件支持.

接口 GOverlay

本接口在maps API 类库之中被GMarker,GPolylineGInfoWindow类所实现.您可以实现本接口来在地图上显示自定义的标记类型.GOverlay的一个实例能够通过GMap2.addOverlay()方法添加到地图.地图会接着调用该实例的GOverlay.initialize()方法来让标注完成在地图上的初始化,之后只要地图显示状态改变,地图就会调用GOverlay.redraw()方法让标注在需要时重新设置自己的位置.标注实力能够通过调用GMap2.getPane()方法来获取一个或多个用来容纳标注DOM对象的层.

构造函数

构造函数

说明

GOverlay()

本构造函数创建该接口的一个虚拟的实现,当您实现这个接口的时候,您的类构造函数必须调用该构造函数来完成构造.

静态方法

静态方法

返回值

说明

getZIndex(latitude)

数字

根据指定的纬度返回一个CSS z-index.它用来根据标记的纬度计算它的显示层级,以便产生3D的效果.

抽象方法

抽象方法

返回值

说明

initialize(map)

在该标注被GMap2.addOverlay()添加到地图之后该方法被地图调用.标记对象能够将自身添加到通过使用GMap2.getPane()方法获取到的多个层之中.

remove()

在标注被GMap2.removeOverlay()方法或GMap2.clearOverlays()方法从地图上移除的时候该方法被地图调用.在这个方法之中标注必须将自己从地图层之中移除.

copy()

GOverlay

返回一个该标注自身的未被初始化的副本.

redraw(force)

当地图的显示改变的时候地图将调用标注的该方法.参数force如果为true代表地图的缩放等级或者像素偏移已经改变,因此标记的像素坐标需要重新计算.

GInfoWindow

GInfoWindow没有构造函数.它由地图类通过创建并通过GMap2.getInfoWindow()方法来访问.

方法

方法

返回值

说明

selectTab(index)

切换到指定索引的标签,这和用户点击该标签名称的效果相同.

hide()

隐藏信息浮窗.注意:该信息浮窗没有被关闭,当调用show()方法之后会再次显示.

show()

显示该信息浮窗如果该信息浮窗被隐藏.

isHidden()

布尔值

返回该信息浮窗是否被隐藏或被关闭.

reset(point, tabs, size, offset?, selectedTab?)

重设信息浮窗的状态,每一个参数都能为空,如果为空则代表相应的状态不变.

getPoint()

GLatLng

返回信息浮窗绑定点的地理点坐标.

getPixelOffset()

GSize

返回地图上信息浮窗指向的点和绑定的点之间的像素差.

getSelectedTab()

数字

返回当前显示的标签的编号,0开始.

事件

事件

参数

说明

closeclick

在信息浮窗的关闭按钮被点击时触发.事件处理句柄能够通过调用GMap2.closeInfoWindow()方法来关闭信息浮窗.

GInfoWindowTab

本类的一组实例能够作为GMap2.openInfoWindowTabs(),GMap2.openInfoWindowTabsHtml(),GMarker.openInfoWindowTabs()GMarker.openInfoWindowTabsHtml()方法的tabs参数,如果该数组包含多个元素,信息浮窗将采用标签的形式显示.每一个InfoWindowTab对象包含两项:content定义信息浮窗的显示内容,label定义信息浮窗的名称标记.这些属性就是构造函数的参数.对于openInfoWindowTabs()方法, content是一个DOM节点.对于openInfoWindowTabsHtml()方法,content是一个HTML字符串.

构造函数

构造函数

说明

GInfoWindowTab(label, content)

创建一个用来传递给openInfoWindowTabs*()方法的tabs参数的信息浮窗标签.

GInfoWindowOptions

本类的一个实例用来作为GMap2GMarkeropenInfoWindow(),openInfoWindowHtml(),openInfoWindowTabs(),openInfoWindowTabsHtml()showMapBlowup()方法之中的opts?参数.该方法没有构造函数,应该直接使用Javascript类的形式构造.

属性

所有的属性都是可选的.

属性

类型

说明

selectedTab

数字

显示指定序号的标签,序号从0开始.

maxWidth

数字

信息浮窗的最大像素宽度.

onOpenFn

函数

在信息浮窗被打开时调用的函数.

onCloseFn

函数

在信息浮窗被关闭时调用的函数.

zoomLevel

数字

只在showMapBlowup()之中使用.信息浮窗的放大地图的缩放等级.

mapType

GMapType

只在showMapBlowup()之中使用.信息浮窗的放大地图的地图类型.

GMarker

GMarker代表在地图上的一个标记.它实现了GOverlay接口,因此可以使用GMap2.addOverlay()方法添加到地图.

每个标记有一个point,代表标记在地图上显示点的地理坐标,和一个icon.如果没有指定icon,则将会使用默认的图标G_DEFAULT_ICON.

在标记被添加到地图之后,地图的信息浮窗能够在地图上显示,标记对象可以触发鼠标事件和信息浮窗事件.

构造函数

构造函数

说明

GMarker(point, icon?, inert?)

在指定位置point使用指定图标iconG_DEFAULT_ICON创建一个标记.如果inert参数为true,该标记将不可点击而且没有任何参数.(2.50版本不再支持)

GMarker(point, opts?)

在指定位置point使用指定的选项GMarkerOptions创建一个标记.默认标记能够点击并使用默认图标G_DEFAULT_ICON. ( 2.50开始支持)

方法

该标记必须被添加到地图才能使用下列方法.

方法

返回值

说明

openInfoWindow(content, opts?)

在标记的图标之上打开地图的信息浮窗.信息浮窗的内容通过一个DOM节点给定.只有GInfoWindowOptions.maxWidth选项可用.

openInfoWindowHtml(content, opts?)

在标记的图标之上打开地图的信息浮窗.信息浮窗的内容通过HTML字符串给定.只有GInfoWindowOptions.maxWidth选项可用.

openInfoWindowTabs(tabs, opts?)

在标记的图标之上打开地图分标签的的信息浮窗.信息浮窗的内容通过包含标签内容的DOM节点数组来给定.只有选项GInfoWindowOptions.maxWidthInfoWindowOptions.selectedTab可用.

openInfoWindowTabsHtml(tabs, opts?)

在标记的图标之上打开地图分标签的的信息浮窗.信息浮窗的内容通过HTML字符串数组数组来给定.只有选项InfoWindowOptions.maxWidthInfoWindowOptions.selectedTab可用.

showMapBlowup(opts?)

在标记的图标之上打开信息浮窗,信息浮窗的内容是一个marker所在位置的更近的地图.只有选项InfoWindowOptions.zoomLevelInfoWindowOptions.mapType可用.

getIcon()

GIcon

返回标记的图标,该图标是在构造函数之中指定的.

getPoint()

GLatLng

返回该标记所指向的地理位置坐标,这是在构造函数setPoint()方法之中指定的.

setPoint(point)

设置该标记所指向的地理位置坐标.

事件

所有以下的事件都只有在地图不在inert状态下才能产生(请看构造函数).

事件

参数

说明

click

当标记图标被点击时触发.注意该事件同时也会以该标记本身作为第一个参数在地图上触发.

dblclick

当标记被双击时触发.注意该事件不会同时在地图上触发,因为地图上双击是设置地图居中的操作.

mousedown

本事件在鼠标在标记图标上按下的时候触发.注意标记会中止该事件的事件冒泡,因此不会让地图开始拖动.

mouseup

本事件在鼠标在标记图标上释放的时候触发.注意标记不会终止该事件的事件冒泡,以防止它将地图的托拽过程弄乱.

mouseover

在鼠标进入标记图标区域时触发.

mouseout

在鼠标离开标记图标区域时触发.

infowindowopen

在地图为标记打开信息浮窗的时候触发.

infowindowclose

在地图关闭标记的信息浮窗时触发,在信息浮窗被关闭,或者在另一个标记上活地图上其他点被打开时都会触发.

remove

当标记冲地图上删除时触发,使用GMap2.removeOverlay()GMap2.clearOverlays()方法都会触发该事件.

GMarkerOptions

该类的一个实例用来作为GMarker的构造函数的opts?参数.没有构造函数,使用Javascript Object形式构造.

属性

所有的属性都是可选的.

属性

类型

说明

icon

GIcon

选择标记的图标,如果没有指定,将使用G_DEFAULT_ICON. (2.50新功能)

clickable

Boolean

指定该标记是否能点击,不能点击的标记将占用更少的系统资源,默认是能够被点击true. (2.50新功能)

title

字符串

该字符串作将被显示为为标记的tooltip,实际上,就相当于HTML元素的title属性. (2.50新功能)

GPolyline

这是地图的一种标注,用来在地图上显示一条折线,如果浏览器支持VML,将使用VML来绘制折线,否则将使用Google服务器上的图片来画出折线.

构造函数

构造函数

说明

GPolyline(points, color?, weight?, opacity?)

使用一组点创建一条折线.color是代表折线颜色的十六进制字符串.weight是以像素为单位的线宽.opacity是从01的数,代表折线的不透明度.

方法

方法

返回值

说明

getVertexCount()

数字

返回折线之中的点的数目. (2.46新功能)

getVertex(index)

GLatLng

返回折线之中指定索引的点. (2.46新功能)

事件

事件

参数

说明

remove

当折线被移除的时候触发,使用GMap2.removeOverlay()GMap2.clearOverlays()都会触发该事件.

GIcon

图标用来指定GMarker在地图上的显示图片.为了浏览器兼容性考虑,指定一个图片是比较复杂的工作.注意您可以使用创建好的默认图标G_DEFAULT_ICON假如您不想自己创建的话.

构造函数

构造函数

说明

GIcon(copy?, image?)

创建新的图标对象.如果在可选参数copy之中给出了另一个图标,则将直接复制该图标的属性到新图标,否则属性将被置空. 可选参数image设置图标的image属性.

常量

常量

说明

G_DEFAULT_ICON

标记所使用的默认图标.

属性

属性

类型

说明

image

字符串

图标使用的前景图片URL地址.

shadow

字符串

图标的阴影图片URL地址.

iconSize

GSize

图标前景图片的大小.

shadowSize

GSize

图标的阴影图片的大小.

iconAnchor

GPoint

图标前景图片上用来锚定到地图上的点相对图片左上角的位置.

infoWindowAnchor

GPoint

图标前景图片上用来被信息浮窗锚定的点相对图片左上角的位置.

printImage

字符串

用来在打印的时候使用的前景图片的URL地址,大小必须和image指定的前景图片相同.

mozPrintImage

字符串

用来在FireFox/Mozilla打印的时候使用的前景图片的URL地址,大小必须和image指定的前景图片相同.

printShadow

字符串

用来打印的阴影图片路径,必须是一个GIF图片,因为大部分的浏览器不支持PNG图片的打印.

transparent

字符串

前景图片的透明版本图片的URL地址,该图片用来在IE之中捕获用户点击事件.该图片必须是一个24位的PNG图片,就是前景图片使用1%不透明度,形状和大小都相同.

imageMap

数字数组

一组代表图标图片上的x/y坐标的整数数组,用来在非IE浏览器之中指定图标图片的可点击区域.

GPoint

一个GPoint地图上的一个像素坐标.注意在第二版之中,它不再用来代表一个地理坐标.地理坐标应该使用新的GLatLng.

在地图坐标系统之中, the x坐标从左到右递增,y从上到下递增.

注意虽然GPoint的两个属性xy是可以修改的,还是最好不要修改它们,创建一个新的实例可能更好.

构造函数

构造函数

说明

GPoint(x, y)

创建一个新的GPoint对象.

属性

属性

类型

说明

x

数字

x坐标,从左向右递增.

y

数字

y坐标,从上向下递增.

方法

方法

返回值

说明

equals(other)

布尔值

返回true如果指定的GPoint有相同的坐标值.

toString()

字符串

返回将xy坐标使用逗号分隔的字符串.

GSize

一个GSize代表地图上一个矩形区域的大小.大小对象有两个参数,widthheight.注意Widthheight不是GPoint之中的x坐标和y坐标.

注意虽然GSize的两个属性widthheight是可以修改的,还是最好不要修改它们,创建一个新的实例可能更好.

构造函数

构造函数

说明

GSize(width, height)

创建一个GSize对象.

属性

属性

类型

说明

width

数字

宽度.

height

数字

高度.

方法

方法

返回值

说明

equals(other)

布尔值

返回true如果指定的GSize有相同的大小.

toString()

字符串

返回将widthheight使用逗号分隔的字符串.

GBounds

GBounds代表地图上的一个矩形像素区域.注意地理像素区域在第二版之中使用GLatLngBounds对象代表.

构造函数

构造函数

说明

GBounds(points)

创建一个新的包含指定points之中所有点的矩形区域.

属性

属性

类型

说明

minX

数字

矩形区域左上角的x坐标.

minY

数字

矩形区域左上角的y坐标.

maxX

数字

矩形区域右下角的x坐标.

maxY

数字

矩形区域右下角的y坐标.

方法

方法

返回值

说明

toString()

字符串

返回矩形区域的坐标字符串,格式如:(minX,minY),(maxX,maxY).

min()

GPoint

返回区域左上角的点坐标.

max()

GPoint

返回区域右下角的点坐标.

containsBounds(other)

布尔值

返回true如果指定区域被本区域整个包含.

extend(point)

扩大本区域以包含指定的点.

intersection(other)

GBounds

返回两个区域的重叠区域,如果两个区域并不重叠,则返回空的区域.

GLatLng

GLatLng是一个使用经度和纬度组成的地理点坐标.

注意虽然通常地图上的经度对应x坐标,纬度对应y坐标,实际上根据地理上的习惯,纬度坐标通常是写在前面的.

注意您不能修改一个GLatLng的坐标,如果您想改变坐标,只能创建一个新的实例.

构造函数

构造函数

说明

GLatLng(lat, lng, unbounded?)

请注意经度和纬度的顺序.如果unbounded属性被设置为true,则将就使用参数之中的值,否则纬度将会被强制转化为-9090之间的值,经度将会被转化为-180180之间的值.

方法

方法

返回值

说明

lat()

数字

返回纬度度数值,如果构造函数之中的unbounded被设置为true,则返回值可能超出-90+90范围.

lng()

数字

返回经度度数值,如果构造函数之中的unbounded被设置为true,则返回值可能超出-180+180范围.

latRadians()

数字

返回纬度弧度值,如果构造函数之中的unbounded被设置为true,则返回值可能超出-PI/2+PI/2范围.

lngRadians()

数字

返回经度弧度值,如果构造函数之中的unbounded被设置为true,则返回值可能超出-PI+PI范围.

equals(other)

布尔值

返回true如果指定坐标值和本坐标相等.

distanceFrom(other)

数字

返回两个点的距离,以米为单位.因为地球被当作椭圆来处理,因此距离可能有0.3%的误差.

toUrlValue()

字符串

返回一个包含该点坐标的字符串,用来在URL参数之中使用,将经度和纬度转化为6位数,以逗号分隔.

属性

这些属性存在是为了和前一版本兼容,不建议使用.

这些属性指向lng()lat()方法的返回值,这些属性使GLatLng能和第一版之中的GPoint一样显示.这样GLatLng在事件处理模型之中非常必要(例如作为事件处理函数的参数).

属性

类型

说明

x

数字

不建议使用.

y

数字

不建议使用.

GLatLngBounds

GLatLngBounds代表一个地理范围,该范围可以跨越180度经线.

构造函数

构造函数

说明

GLatLngBounds(sw?, ne?)

使用东北和西南两个角的点创建一个矩形地理范围.

方法

方法

返回值

说明

equals(other)

布尔值

返回true如果该范围和指定的范围相同.

contains(latlng)

布尔值

返回true如果该范围包含指定的地理点.

intersects(other)

布尔值

返回该范围和指定的范围是否有重叠区域.

containsBounds(other)

布尔值

返回该范围是否包含指定范围.

extend(latlng)

Enlarges this rectangle such that it contains the given point. In longitude direction, it is enlarged in the smaller of the two possible ways. If both are equal, it is enlarged at the eastern boundary.

getSouthWest()

GLatLng

Returns the point at the south-west corner of the rectangle.

getNorthEast()

GLatLng

Returns the point at the north-east corner of the rectangle.

toSpan()

GLatLng

Returns a GLatLng whose cordinates represent the size of this rectangle.

isFullLat()

布尔值

Returns true if this rectangle extends from the south pole to the north pole.

isFullLng()

布尔值

Returns true if this rectangle extends fully around the earth in the longitude direction.

isEmpty()

布尔值

Returns true if this rectangle is empty.

接口 GControl

This 接口 is implemented by all controls. You can implement it in order to provide a custom control for the map. Controls are added to the map using the GMap2.addControl() method.

In contrast to overlays, which are positioned relative to the map, controls are positioned relative to the map view, i.e. they don't move when the map moves.

构造函数

构造函数

说明

GControl(printable?, selectable?)

Creates the prototype instance for a new control class. Flag printable indicates that the control should be visible in the print output of the map. Flag selectable indicates that the control will contain text that should be selectable.

方法

These methods will be called by the map when the control is added to the map using GMap2.addControl(). Thus, these methods will not be called by you, but they will be implemented by you.

方法

返回值

说明

printable()

布尔值

Returns to the map if the control should be printable.

selectable()

布尔值

Returns to the map if the control contains selectable text.

initialize(map)

HTML节点

Will be called by the map so the control can initialize itself. The control will use the method GMap2.getContainer() to get hold of the DOM element that contains the map, and add itself to it. It returns the added element.

getDefaultPosition()

GControlPosition

Returns to the map the position in the map view at which the control appears by default. This will be overridden by the second argument to GMap2.addControl().

GControlPosition

This class described the position of a control in the map view. It consists of a corner relative to where the control is postioned, and an offset that determines this position. It can be passed as optional argument position to the method GMap2.addControl(), and it is returned from method GControl.getDefaultPosition().

构造函数

构造函数

说明

GControlPosition(anchor, offset)

Creates a specification for a control position.

枚举 GControlAnchor

常量

常量

说明

G_ANCHOR_TOP_RIGHT

The control will be anchored in the top right corner of the map.

G_ANCHOR_TOP_LEFT

The control will be anchored in the top left corner of the map.

G_ANCHOR_BOTTOM_RIGHT

The control will be anchored in the bottom right corner of the map.

G_ANCHOR_BOTTOM_LEFT

The control will be anchored in the bottom left corner of the map.

GControl

These implementations of 接口 GControl are available.

构造函数

构造函数

说明

GSmallMapControl()

Creates a control with buttons to pan in four directions, and zoom in and zoom out.

GLargeMapControl()

Creates a control with buttons to pan in four directions, and zoom in and zoom out, and a zoom slider.

GSmallZoomControl()

Creates a control with buttons to zoom in and zoom out.

GScaleControl()

Creates a control that displays the map scale.

GMapTypeControl()

Creates a control with buttons to switch between map types.

GMapType

The are some predefined map types. This class can be used to define custom map types. In order to pass them to the map, use the GMap2 constructor, or the GMap2.addMapType() method.

This class can also be subclassed. Constructor arguments can be omitted if instantiated as a prototype. A subclass constructor must invoke the GMapType constructor using call().

构造函数

构造函数

说明

GMapType(layers, projection, name, opts?)

Constructs a map type with the given tile layers, projection, name, and optional parameters.

方法

These methods are mostly called by the map that this maptype is passed to, but some methods may also be called from outside the map, e.g. getBoundsZoomLevel().

方法

返回值

说明

getSpanZoomLevel(center, span, viewSize)

数字

Returns to the map the zoom level at which the map section defined by center and span fits into the map view of the given size in pixels.

getBoundsZoomLevel(bounds, viewSize)

Returns to the map the zoom level at which the map section defined by bounds fits into the map view of the given size in pixels.

getName(opt_short)

字符串

Returns to the map the name of the map type to be used as the button label in the GMapTypeControl.

getProjection()

GProjection

Returns to the map the projection of this map type.

getTileSize()

数字

Returns to the map the map tile size in pixels of this map type. The tiles are assumed to be quadratic. All tile layers have the same tile size.

getTileLayers()

GTileLayer数组

Returns to the map the array of tile layers.

getMinimumResolution(latlng?)

数字

Returns to the map the lowest zoom level at which this map type is defined.

getMaximumResolution(latlng?)

数字

Returns to the map the highest zoom level at which this map type is defined.

getTextColor()

字符串

Returns to the map the color that is best used for text that is overlaid on the map. Used for the color of the text of the copyright message displayed by the copyroght control.

getLinkColor()

字符串

Returns to the map the color that is best used for a hyperlink that is overlaid on the map. Used for the color of the link to the terms of use displayed by the copyroght control.

getErrorMessage()

字符串

Returns to the map the error message that is displayed in areas or on zoom level where this map type doesn't have map tiles.

getCopyrights(bounds, zoom)

字符串数组

Returns to the map the copyright messages appropriate for the region described by bounds at the given zoom level. This is used by the GCopyrightControl to display the copyright message on the map.

getUrlArg()

字符串

Returns to the map a value that is used as a URL paramater value to identify this map type in permalinks to the current map view. This is currently only used by the maps application.

常量

常量

说明

G_NORMAL_MAP

This is the normal street map type.

G_SATELLITE_MAP

This map type shows Google Earth satellite images.

G_HYBRID_MAP

This map type shows transparent street maps over Google Earth satellite images.

G_DEFAULT_MAP_TYPES

An array of all three predefined map types described above.

事件

事件

参数

说明

newcopyright

copyright

This event is fired when a new copyright is added to the copyright collection of one of the tile layers contained in this map type.

GMapTypeOptions

Instances of this class are used as the opts? argument to the GMapType constructor. There is no constructor for this class. Instead, this class is instantiated as a javascript object literal.

属性

属性

类型

说明

shortName

字符串

Sets the short name of the map type that is returned from GMapType.getName(true). Default is the same as the name.

urlArg

字符串

Sets the url argument of the map type that is returned from GMapType.getUrlArg(). Default is the empty string.

maxResolution

数字

Sets the maximum zoom level of this map type, returned by GMapType.getMaximumResolution(). Default is the maximum of all tile layers.

minResolution

数字

Sets the minimum zoom level of this map type, returned by GMapType.getMinimumResolution(). Default is the minimum of all tile layers.

tileSize

数字

Set the tile size returned by GMapType.getTileSize(). Default is 256.

textColor

字符串

Sets the text color returned by GMapType.getTextColor(). Default is "black".

linkColor

字符串

Sets the text color returned by GMapType.getLinkColor(). Default is "#7777cc".

errorMessage

字符串

Sets the error message returned by GMapType.getErrorMessage(). Default is the empty string.

接口 GTileLayer

You implement this 接口 in order to provide custom map tile layers. Your implementation of this 接口 should use an instance of GTileLayer as a prototype, because this implements the copyright handling for you.

构造函数

构造函数

说明

GTileLayer(copyrights, minResolution, maxResolution)

Constructor arguments can be omitted if instantiated as a prototype. A Subclass constructor must invoke this constructor using call().

方法

These methods are called by the map and the map type to which this tile layer is passed. You will need to implement the methods marked abstract when you implement a custom tile layer.

方法

返回值

说明

minResolution()

数字

Returns to the map type the lowest zoom level of this tile layer.

maxResolution()

数字

Returns to the map type the highest zoom level of this tile layer.

getTileUrl(tile, zoom)

字符串

Abstract. Returns to the map the URL of the map tile with the tile indices given by the x and y properties of the GPoint, at the given zoom level.

isPng()

布尔值

Abstract. Returns to the map whether the tiles are in PNG image format and hence can be transparent. Otherwise GIF is assumed.

getOpacity()

数字

Abstract. Returns to the map the opacity with which to display this tile layer. 1.0 is opaque, 0.0 is transparent.

事件

事件

参数

说明

newcopyright

copyright

This event is fired when a new copyright is added to the copyright collection of this tile layer.

GCopyrightCollection

You use this class to manage copyright messages displayed on maps of custom map type. If you don't implement custom map types, then you don't need to use this class. A copyright collection contains information about which copyright to display for which region on the map at which zoom level. This is very important for map types that display heterogenous data such as the satellite map type.

构造函数

构造函数

说明

GCopyrightCollection(prefix?)

Copyright messages produced from this copyright collection will have the common prefix given as the argument. Example: "Imagery (C) 2006"

方法

方法

返回值

说明

()

addCopyright(copyright)

Adds a copyright information object to the collection.

getCopyrights(bounds, zoom)

字符串数组

Returns all copyright strings that are pertinent for the given map region at the given zoom level. Example: [ "Google", "Keyhole" ]

getCopyrightNotice(bounds, zoom)

字符串

Returns the prefix and all relevant copyright strings that are pertinent for the given map region at the given zoom level. Example: "Imagery (C) 2006 Google, Keyhole"

事件

事件

参数

说明

newcopyright

copyright

This event is fired when a new copyright was added to this copyright collection.

GCopyright

A copyright object contains information about which copyright message applies to a region of the map given by a rectangle, at a given zoom level. You need this object only if you implement custom map types or tile layers.

构造函数

构造函数

说明

GCopyright(id, bounds, minZoom, text)

Creates a copyright information object with the given properties.

属性

属性

类型

说明

id

数字

A unique identifier for this copyright information.

minZoom

数字

The lowest zoom level at which this information applies.

bounds

GLatLngBounds

The region to which this information applies.

text

字符串

The text of the copyright message.

接口 GProjection

This is the 接口 for map projections. A map projection instance is passed to the constructor of GMapType. This 接口 is implemented by the GMercatorProjection, which is used by all predefined map types. You can implement this 接口 if you want to define map types with different map projections.

方法

These methods are called by the map. You need to implement them.

方法

返回值

说明

fromLatLngToPixel(latlng, zoom)

GPoint

Returns the map coordinates in pixels for the point at the given geographical coordinates, and the given zoom level.

fromPixelToLatLng(pixel, zoom, unbounded?)

Returns the geographical coordinates for the point at the given map coordinates in pixels, and the given zoom level. Flag unbounded causes the geographical longitude coordinate not to wrap when beyond the -180 or 180 degrees meridian.

tileCheckRange(tile, zoom, tilesize)

Returns to the map if the tile index is in a valid range for the map type. Otherwise the map will display an empty tile. It also may modify the tile index to point to another instance of the same tile in the case that the map contains more than one copy of the earth, and hence the same tile at different tile coordinates.

getWrapWidth(zoom)

Returns to the map the periodicity in x-direction, i.e. the number of pixels after which the map repeats itself because it wrapped once round the earth. By default, returns Infinity, i.e. the map will not repeat itself. This is used by the map to compute the placement of overlays on map views that contain more than one copy of the earth (this usually happens only at low zoom levels). (Since 2.46)

GMercatorProjection

This implementation of the GProjection接口 for the mercator projection is used by all predefined map types.

构造函数

构造函数

说明

GMercatorProjection(zoomlevels)

Creates a mercator projection for the given number of zoom levels.

方法

方法

返回值

说明

fromLatLngToPixel(latlng, zoom)

GPoint

See GProjection.

fromPixelToLatLng(pixel, zoom, unbounded?)

GLatLng

See GProjection.

checkTileRange(tile, zoom, tilesize)

See GProjection.

getWrapWidth(zoom)

See GProjection. Mercator projection is periodic in longitude direction, therefore this returns the width of the map of the entire Earth in pixels at the given zoom level. (Since 2.46)

namespace GEvent

This namespace contains functions that you use to register event handlers, both for custom events and for DOM events, and to fire custom events. All the events defined by this API are custom events that are internally fired by GEvent.triggerEvent().

静态方法

静态方法

返回值

说明

addListener(source, event, handler)

GEventListener

Registers an event handler for a custom event on the source object. Returns a handle that can be used to eventually deregister the handler. The event handler will be called with this set to the source object.

addDomListener(source, event, handler)

GEventListener

Registers an event handler for a DOM event on the source object. The source object must be a DOM Node. Returns a handle that can be used to eventually deregister the handler. The event handler will be called with this set to the source object. This function uses the DOM methods for the current browser to register the event handler.

removeListener(handle)

Removes a handler that was installed using addListener() or addDomListener().

clearListeners(source, event)

Removes all handlers on the given object for the given event that were installed using addListener() or addDomListener().

clearInstanceListeners(source)

Removes all handlers on the given object for all events that were installed using addListener() or addDomListener().

trigger(source, event, ...)

Fires a custom event on the source object. All arguments after event are passed as arguments to the event handler functions.

bind(source, event, object, method)

Registers an invocation of the method on the given object as the event handler for a custom event on the source object. Returns a handle that can be used to eventually deregister the handler.

bindDom(source, event, object, method)

Registers an invocation of the method on the given object as the event handler for a custom event on the source object. Returns a handle that can be used to eventually deregister the handler.

callback(object, method)

Returns a closure that calls method on object.

callbackArgs(object, method, ...)

Returns a closure that calls method on object with the given arguments.

事件

事件

参数

说明

clearlisteners

event?

This event is fired on object when clearListeners() or clearInstanceListeners() is called on that object. Of course, the event is fired before the functions are executed.

GventListener

This class is opaque. It has no methods and no constructor. Its instances are returned from GEvent.addListener() or GEvent.addDomListener() and are eventually passed back to GEvent.removeListener().

namespace GXmlHttp

This namespace provides a factory method to create XmlHttpRequest instances in a browser independent way.

静态方法

静态方法

返回值

说明

create()

GXmlHttp

Factory to create a new instance of XmlHttpRequest.

namespace GXml

This namespace provides static methods to handle XML documents and document fragments.

静态方法

静态方法

返回值

说明

parse(xmltext)

HTML节点

Parses the given string as XML text and returns a DOM representation. If the browser doesn't support XML parsing natively, this returns the DOM node of an empty DIV element.

value(xmlnode)

字符串

Returns the text value (i.e., only the plain text content) of the XML document fragment given in DOM representation.

GXslt

This class provides methods to apply XSLT to XML in a browser-independent way.

静态方法

静态方法

返回值

说明

create(xsltnode)

GXslt

Creates a GXslt instance from the XSLT stylesheet given as DOM representation.

transformToHtml(xmlnode, htmlnode)

布尔值

Uses the XSLT stylesheet given in the constructor of this GXslt instance to transform the XML document given as DOM representation in xmlnode. Appends the resulting HTML document fragment to the given htmlnode. This only works if the browser natively supports XSL transformations, in which case it will return true. Otherwise, this function will do nothing and return false.

namespace GLog

This namespace contains some static methods that help you to debug web applications. When you use one of the write*() methods for the first time, a floating window opens on the page and displays the written messages.

静态方法

静态方法

返回值

说明

write(message, color?)

Writes the message as plain text into the log window. HTML markup characters will be escaped so that they are visible as characters.

writeUrl(url)

Writes a link to the given URL into the log window.

writeHtml(html)

Writes text as HTML in the log window.

函数 GDownloadUrl

本函数提供一个方便的方法来异步下载一个URL资源.注意,因为请求的时候使用了XmlHttpRequest对象,因此会受到脚本跨域访问的限制,URL必须指向到和网页同在一个服务器的资源.因此,通常在url参数之中使用绝对路径通常都没有什么必要,最好只使用相对路径.

函数

函数

返回值

说明

GDownloadUrl(url, onload)

下载指定URL的资源并在下载完成之后以下载文件的内容为第一个参数来调用onload函数,以HTTP 响应状态码作为第二个参数.这个方法会受到跨域访问的限制.后台使用浏览器的XmlHttpRequest.

函数 GBrowserIsCompatible

本函数判断maps API能否在当前的浏览器之中执行.

函数

函数

返回值

说明

GBrowserIsCompatible()

布尔值

返回true如果API支持当前在浏览器上运行.

函数 GUnload

您能够调用该方法来让map API清除内部的数据来清空内存.这可以帮助你解决网络程序之中的内存泄漏问题.您应该在页面的unload事件之中调用该函数.在本函数调用之后您页面之中的地图功能不再存在.

函数

函数

返回值

说明

GUnload()

为了防止内存泄漏而取消注册所有的事件处理器,应该在页面的unload事件之中执行.


评论

# re: Google Maps API 2.0 参考文档(ZZ)  回复  更多评论   

2010-12-24 17:55 by 路过
好东西!很有帮助!谢谢楼主!

只有注册用户登录后才能发表评论。


网站导航: