2013-05-07 205 views
1

我想地理位置添加到我的位於http://alert.fcd.maricopa.gov/alert/Google/v3/mobile.html 地圖移動版。地理位置與谷歌地圖V3

我通過這個JavaScript地圖加載文件 http://alert.fcd.maricopa.gov/alert/Google/v3/js/mobilemap_v3.js。你 會發現這個文件的該行46 -

map = new google.maps.Map($('#map_canvas')[0],myOptions); 

我試圖在https://developers.google.com/maps/documentation/javascript/examples/map-geolocation的地理位置例子,在http://www.w3schools.com/html/html5_geolocation.asp的W3 HTML5的地理定位方法。但我的地圖加載通過jquery和不使用

map = new google.maps.Map(document.getElementById('map-canvas'), 
mapOptions); 

像所有的例子。

如果我用 document.getElementById替換第46行中的$,那麼我可以獲取地理定位,但是然後我的傳感器/製造商都不會顯示 。

有誰知道我怎麼能拿地理位置與我 標記/數據仍在加載工作?

+0

這將有助於如果我們能看到你實際使用的AJAX代碼。 – Blazemonger 2013-05-07 19:37:30

+0

CSS爲地圖(#map_canvas)是在 'http://alert.fcd.maricopa.gov/alert/Google/v3/css/mobile.css'。您可以通過瀏覽器查看mobile.html的頁面源代碼。 – MillerC 2013-05-07 19:46:05

+0

您應該直接在問題中爲後代發佈您的問題代碼(JS,不僅僅是CSS)。您的外部頁面可能隨時發生變化,在您收到有用答案後幾乎肯定會發生變化。 – Blazemonger 2013-05-07 19:57:29

回答

2

找到一個答案!我用geolocationmarker-compiled.js(在http://code.google.com/p/google-maps-utility-library-v3/source/browse/trunk/geolocationmarker/src/geolocationmarker-compiled.js?r=379),然後加入

var GeoMarker; 

GeoMarker = new GeolocationMarker(); 
    GeoMarker.setCircleOptions({ 
    fillColor: '#808080'}); 

    google.maps.event.addListenerOnce(GeoMarker, 'position_changed', function() { 
     map.setCenter(this.getPosition()); 
     map.fitBounds(this.getBounds()); 
    }); 

    google.maps.event.addListener(GeoMarker, 'geolocation_error', function(e) { 
     alert('There was an error obtaining your position. Message: ' + e.message); 
    }); 

    GeoMarker.setMap(map); 

和它的偉大工程。如果任何人想要做同樣的事情,那麼移動地圖工作位於http://alert.fcd.maricopa.gov/alert/Google/v3/mobile.html,移動地圖代碼位於mobilemap_v3.js文件中。