[英]Geolocation with Google Map V3
I would like to add geolocation to the mobile version of my map located at http://alert.fcd.maricopa.gov/alert/Google/v3/mobile.html
. 我想将地理位置添加到位于
http://alert.fcd.maricopa.gov/alert/Google/v3/mobile.html
地图的移动版本中。
My map loads through this JavaScript file http://alert.fcd.maricopa.gov/alert/Google/v3/js/mobilemap_v3.js
. 我的地图通过此JavaScript文件
http://alert.fcd.maricopa.gov/alert/Google/v3/js/mobilemap_v3.js
加载。 You will notice that line 46 of this file is - 您会注意到该文件的第46行是-
map = new google.maps.Map($('#map_canvas')[0],myOptions);
I have tried the Geolocation example at https://developers.google.com/maps/documentation/javascript/examples/map-geolocation
and the W3 HTML5 Geolocation method at http://www.w3schools.com/html/html5_geolocation.asp
. 我已经在
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
。 But my map loads through jquery and doesn't use 但是我的地图通过jQuery加载并且不使用
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
like all the examples. 像所有例子一样
I can get the geolocation to work if I replace the $ in line 46 with document.getElementById but then none of my sensors/makers will display. 如果将第46行中的$替换为document.getElementById,则可以使地理位置正常工作,但是我的传感器/制造商均不会显示。
Does anyone know how I could get the geolocation working with my markers/data still loading? 有谁知道我如何才能使地理定位与仍在加载的标记/数据一起工作?
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
我使用了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);
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.
如果有人希望做相同的事情,则具有地理位置功能的移动地图位于http://alert.fcd.maricopa.gov/alert/Google/v3/mobile.html,并且位于mobilemap_v3.js文件中的地理位置代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.