1

我想将地理位置添加到我位于的移动版地图中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);  

我已经尝试过 Geolocation 示例https://developers.google.com/maps/documentation/javascript/examples/map-geolocation和 W3 HTML5 Geolocation 方法http://www.w3schools.com/html/html5_geolocation.asp。但是我的地图通过 jquery 加载并且不使用

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

像所有的例子一样。

如果我用 document.getElementById 替换第 46 行中的 $,我可以让地理位置工作,但我的传感器/制造商都不会显示。

有谁知道我怎样才能在我的标记/数据仍在加载的情况下获得地理位置?

4

1 回答 1

2

Found an answer to this! I used geolocationmarker-compiled.js (at http://code.google.com/p/google-maps-utility-library-v3/source/browse/trunk/geolocationmarker/src/geolocationmarker-compiled.js?r=379) and then added

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);

and it works great. Mobile map with Geolocation working is located at http://alert.fcd.maricopa.gov/alert/Google/v3/mobile.html and the geolocation code in in the mobilemap_v3.js file if anyone is looking to do the same thing.

于 2013-05-22T19:03:21.433 回答