1
/*
2
*Author:Ryan Ding
3
*Date:2010-03-09
4
*Summary:GMapMark 类 将 Google API Local Search 查询到的内容写入google map中。
5
*/
6
7
var
GMapMaker
=
8
function
() {
9
var
gSize
=
new
GSize(
16
,
16
);
10
var
restaurantIcon
=
new
GIcon(G_DEFAULT_ICON);
11
restaurantIcon.image
=
"
restaurant.png
"
;
12
restaurantIcon.iconSize
=
gSize;
13
restaurantIcon.iconAnchor
=
new
GPoint(
8
,
20
);
14
restaurantIcon.shadow
=
""
;
15
16
var
bankIcon
=
new
GIcon(G_DEFAULT_ICON);
17
bankIcon.image
=
"
bank.png
"
;
18
bankIcon.iconSize
=
gSize;
19
bankIcon.iconAnchor
=
new
GPoint(
8
,
20
);
20
bankIcon.shadow
=
""
;
21
22
var
shoppingIcon
=
new
GIcon(G_DEFAULT_ICON);
23
shoppingIcon.image
=
"
shopping.png
"
;
24
shoppingIcon.iconSize
=
gSize;
25
shoppingIcon.iconAnchor
=
new
GPoint(
8
,
20
);
26
shoppingIcon.shadow
=
""
;
27
28
var
schoolIcon
=
new
GIcon(G_DEFAULT_ICON);
29
schoolIcon.image
=
"
school.png
"
;
30
schoolIcon.iconSize
=
gSize;
31
schoolIcon.iconAnchor
=
new
GPoint(
8
,
20
);
32
schoolIcon.shadow
=
""
;
33
34
var
hospitalIcon
=
new
GIcon(G_DEFAULT_ICON);
35
hospitalIcon.image
=
"
hospital.png
"
;
36
hospitalIcon.iconSize
=
gSize;
37
hospitalIcon.iconAnchor
=
new
GPoint(
8
,
20
);
38
hospitalIcon.shadow
=
""
;
39
40
var
marketIcon
=
new
GIcon(G_DEFAULT_ICON);
41
marketIcon.image
=
"
market.png
"
;
42
marketIcon.iconSize
=
gSize;
43
marketIcon.iconAnchor
=
new
GPoint(
8
,
20
);
44
marketIcon.shadow
=
""
;
45
46
47
var
_opts
=
{
48
keyWord:
"
餐厅
"
,
49
latlng:
new
GLatLng(
24.467571
,
118.113155
),
50
icon:
new
GIcon(G_DEFAULT_ICON),
51
zoom:
14
,
52
searchSize:
8
53
};
54
55
//
alert("GMarker init");
56
google.load(
'
search
'
,
'
1
'
);
57
58
var
initSettings
=
function
(opts) {
59
_opts.latlng
=
opts.latlng
||
new
GLatLng(
24.467571
,
118.113155
);
60
_opts.zoom
=
14
;
61
}
62
63
var
addMark
=
function
(latlng, title, desc, icon_) {
64
var
mark
=
new
GMarker(latlng, { icon: icon_
||
new
GIcon(G_DEFAULT_ICON), title: title });
65
var
html
=
desc;
66
GEvent.addListener(mark,
'
click
'
,
function
() {
67
mark.openInfoWindowHtml(html);
68
});
69
//
mark.openInfoWindowHtml(html);
70
this
.map.addOverlay(mark);
71
};
72
73
var
proccesslocalSearch
=
function
(gSearch, keyWord, icon_) {
74
gSearch.setResultSetSize(GSearch.LARGE_RESULTSET);
//
LARGE_RESULTSET FILTERED_CSE_RESULTSET
75
gSearch.setCenterPoint(_opts.latlng, _opts.zoom);
76
gSearch.setSearchCompleteCallback(
this
,
function
() {
77
for
(
var
i
=
; i
<
gSearch.results.length; i
++
) {
78
addMark(
new
GLatLng(gSearch.results[i].lat, gSearch.results[i].lng),
79
gSearch.results[i].title,
80
gSearch.results[i].title, icon_);
81
}
82
});
83
gSearch.execute(keyWord);
84
}
85
86
var
onLoadBank
=
function
() {
87
var
localSearch
=
new
google.search.LocalSearch();
88
proccesslocalSearch(localSearch,
"
银行
"
, bankIcon);
89
}
90
91
var
onLoadSchool
=
function
() {
92
var
localSearch
=
new
google.search.LocalSearch();
93
proccesslocalSearch(localSearch,
"
学校
"
, schoolIcon);
94
95
}
96
97
var
onLoadRestaurant
=
function
() {
98
var
localSearch
=
new
google.search.LocalSearch();
99
proccesslocalSearch(localSearch,
"
餐饮
"
, restaurantIcon);
100
101
}
102
103
var
onLoadMarket
=
function
() {
104
var
localSearch
=
new
google.search.LocalSearch();
105
proccesslocalSearch(localSearch,
"
超市
"
, restaurantIcon);
106
107
}
108
109
var
onLoadHospital
=
function
() {
110
var
localSearch
=
new
google.search.LocalSearch();
111
proccesslocalSearch(localSearch,
"
医院
"
, hospitalIcon);
112
113
}
114
115
116
return
{
117
autoSetMapPoint:
function
(ops) {
118
//
alert("autoSetMapPoint");
119
initSettings(ops);
120
google.setOnLoadCallback(onLoadBank);
121
google.setOnLoadCallback(onLoadSchool);
122
google.setOnLoadCallback(onLoadRestaurant);
123
google.setOnLoadCallback(onLoadMarket);
124
google.setOnLoadCallback(onLoadHospital);
125
126
}
127
}
128
} ();
129