簡體   English   中英

使用Google Map V3進行地理位置定位

[英]Geolocation with Google Map V3

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

我的地圖通過此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嘗試了Geolocation示例,並在http://www.w3schools.com/html/html5_geolocation.asp嘗試了W3 HTML5 Geolocation方法http://www.w3schools.com/html/html5_geolocation.asp 但是我的地圖通過jQuery加載並且不使用

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

像所有例子一樣

如果將第46行中的$替換為document.getElementById,則可以使地理位置正常工作,但是我的傳感器/制造商均不會顯示。

有誰知道我如何才能使地理定位與仍在加載的標記/數據一起工作?

找到了答案! 我使用了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文件中的地理位置代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM