gpt4 book ai didi

javascript - 使用 Google Map V3 进行地理定位

转载 作者:行者123 更新时间:2023-11-30 18:03:09 25 4
gpt4 key购买 nike

我想在我的移动版本中添加地理定位 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com