google map V3 笔记

[size=medium]
[b]google map javascript api v3[/b]
Version 3 of this API is especially designed to be faster and more applicable to mobile devices, as well as traditional desktop browser applications.

[b]1.一切都是围绕google.maps.Map这个地图对象设计[/b]
1).创建地图对象
var map = new google.maps.Map(node, mapOptions);
其中node是DOM对象, document.getElementById('map_canvas');
var mapOptions = {
center: new google.maps.LatLng(23.445,111.334),
mapTypeId: google.maps.MapTypeId.ROADMAP
}

2)地图对象参数选项
其中center, mapTypeId这两个属性是必须的
其他可选

[b]2.地图事件[/b]
1).用户事件(比如click)
are propagated from the DOM to the Google Maps API. These events are separate and distinct from standard DOM events
2).地图对象状态改变事件
MVC state change notifications reflect changes in Maps API objects and are named using a property_changed convention
3)绑定事件
google.maps.event.addListener(MVC-object, 'event', callback);
例如:
[code=javascript]
google.maps.event.addListener(map, 'click', function(event){
alert(event.latLng);
});
[/code]
注意MVC状态改变事件并没有传递类似event的参数,需要自己去getProperty();

[b]3.地图控件Controls[/b]
1)内置控件
a.zoom control
b.pan control
c.scale control
d.mapType control
e.street view control
这些内置控制需要在地图选项里定义外观与可见性(mapOptions)
关闭默认的控件UI
mapOptions: disableDefaultUI=true;
关闭添加内置控件:
[code=javascript]
{
panControl: boolean,
zoomControl: boolean,
mapTypeControl: boolean,
scaleControl: boolean,
streetViewControl: boolean
}[/code]

2)定制Control: (相对地图位置不变)
a.css 元素样式
b.通过事件控制器与用户或map交互
c.Create a <div> element to hold the control and add this element to the Map's controls property.
[code=javascript]
google.maps.event.addDomListener(outer, 'click', function() {
map.setCenter(chicago)
});[/code]

Positioning Custom Controls:
var controlDiv = document.createElement('DIV');
var myControl = new MyControl(controlDiv);
controlDiv.index = 1;
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlDiv);

[b]4.Overlay (相对于地理位置不变)[/b]
与Control的区别是附在地图位置图层上
Overlays reflect objects that you "add" to the map to designate points, lines, areas, or collections of objects.
1)single location: marker, icon
2)lines on the map: polyline
3)Areas of arbitrary shape on the map: polygon
4)Map layers may be displayed using overlay map types
5)The info window is also a special kind of overlay for displaying content (usually text or images) within a popup balloon on top of a map at a given location
6)You may also implement your own custom overlays. These custom overlays implement the OverlayView interface

[b]add overlay to map:[/b]
可以使用overlay的option中标记map对象
也可以使用setMap(map)
[b]remove overlay from map:[/b]
setMap(null);//set map to null
这个时候并没有销毁overlay对象,只是不在map中显示而已,
如果确实要销毁overlay对象, set overlay itself to null;
程序员需要自己去管理自己的overlay的生命周期

[b]5.Marker[/b]
标记一个location
markerOptions: latlng, map, animation, icon

[b]6.Polyline[/b]
A Polyline object consists of an array of LatLng locations, and creates a series of line segments that connect those locations in an ordered sequence.

Polyline Arrays
var path = poly.getPath() 返回MVCArray, 包含Latlng对象
path.push(latlng)
path.getAt(), path.insertAt(), path.removeAt()

GroundOverlay: 可以在overlay里放图片, polygon则不行

[b]7.Info Window :提示层[/b]
创建了var info =InfoWindow(opts)对象后,
是不在地图上显示的,需要调用info.open(map, marker);
marker可选, 如果没有marker,则使用latlng属性的坐标
gmap version 2默认只有一个infowindow对象的, v3是可以创建多个infowindow对象了

[b]8.Layers Overview[/b]
Layers are objects on the map that consist of one or more separate items, but are manipulated as a single unit.
The Maps API has several types of layers:
a.KmlLayer objects render KML and GeoRSS elements into a Maps API V3 tile overlay.
b.FusionTablesLayer objects render data contained in Google Fusion Tables.
c.The TrafficLayer object renders a layer depicting traffic conditions and overlays representing traffic.
d.The BicyclingLayer object renders a layer of bike paths and/or bicycle-specific overlays into a common layer.


[b]9.地图服务services[/b]
geocoding, directions, elevation, street view, Maximum Zoom Imagery
1).Geocoding: address to latlng
var geocoder = new google.maps.Geocoder();
异步请求服务

[code=javascript]
geocoder.geocode({address:'guangdong'}, function(results, status){

});[/code]
2).Reverse Geocoding (Address Lookup)
同样使用geocoder调用远程服务
使用方式,返回格式等参考The Google Geocoding API
[url]http://code.google.com/apis/maps/documentation/geocoding/index.html[/url]

[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值