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

标签 javascript jquery google-maps-api-3 geolocation

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

相关文章:

javascript - AngularJS - 您是否从服务/工厂返回 promise 或数据?

javascript - JQuery Datepicker 在代码隐藏中获取选定月份更改事件

javascript - 实际 IE6 Png 修复

javascript - 下拉列表未填充 - Angular JS

javascript - 从加载的 KML 向标记添加点击事件

jquery - Google Maps API V3 fitbounds() 缩小但从不放大

google-maps-api-3 - Google Places API:如何使用多种类型?

javascript - 窗口处于事件状态时,前端停止更新元素

javascript - 在 JavaScript 中等待 Promise 和事件监听器

jquery - 如何在 .NET 应用程序中引用 jQuery 的绝对路径