繁体   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