我想在我的移动版本中添加地理定位
map 位于 http://alert.fcd.maricopa.gov/alert/Google/v3/mobile.html
。
我的 map 通过这个 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 中的 W3 HTML5 Geolocation 方法://www.w3schools.com/html/html5_geolocation.asp
。但是我的 map 通过 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);
而且效果很好。具有地理定位功能的移动 map 位于 http://alert.fcd.maricopa.gov/alert/Google/v3/mobile.html以及 mobilemap_v3.js 文件中的地理位置代码(如果有人希望做同样的事情)。
关于javascript - 使用 Google Map V3 进行地理定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16426793/