File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,7 @@ <h1 id="web-title">全台灣郵筒位置地圖</h1>
160160 markers . forEach ( function ( marker ) {
161161 marker . setMap ( null ) ;
162162 } ) ;
163+
163164 markers = [ ] ;
164165
165166 var bounds = new google . maps . LatLngBounds ( ) ;
@@ -191,6 +192,23 @@ <h1 id="web-title">全台灣郵筒位置地圖</h1>
191192 } ) ;
192193 map . fitBounds ( bounds ) ;
193194 } ) ;
195+ if ( navigator . geolocation ) {
196+ navigator . geolocation . getCurrentPosition ( function ( position ) {
197+ var pos = {
198+ lat : position . coords . latitude ,
199+ lng : position . coords . longitude
200+ } ;
201+ var marker = new google . maps . Marker ( {
202+ position : pos ,
203+ map : map
204+ } ) ;
205+ map . setZoom ( 17 ) ;
206+ map . setCenter ( pos ) ;
207+ } ) ;
208+ } else {
209+ // Browser doesn't support Geolocation
210+ alert ( "未允許或遭遇錯誤!" ) ;
211+ }
194212 }
195213
196214 </ script >
You can’t perform that action at this time.
0 commit comments