Global Map, position via GeoLocation (JavaScript(
-
Hi Guys,
I want to have GeoLocation in my Global Map. Therefor I went through all the javascript and PHP files to figuere out where the Google Maps coding including API is done. If I’m not wrong the global Map is coded in the Events_manager.js file.
There fore I added the following code in the function em_maps_load_loacation(el), but it doesn’t work. In my understanding with this code it would just create a info.Window at the position of the customer.
I’m really a beginner in coding so it’s difficult to find the failure…
Hope someone can help! Thanks.
function em_maps_load_location(el){ el = jQuery(el); var map_id = el.attr('id').replace('em-location-map-',''); em_LatLng = new google.maps.LatLng( jQuery('#em-location-map-coords-'+map_id+' .lat').text(), jQuery('#em-location-map-coords-'+map_id+' .lng').text()); //extend map and markers via event triggers var map_options = { zoom: 14, center: em_LatLng, mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: false, gestureHandling: 'cooperative' }; if( typeof EM.google_map_id_styles == 'object' && typeof EM.google_map_id_styles[map_id] !== 'undefined' ){ console.log(EM.google_map_id_styles[map_id]); map_options.styles = EM.google_map_id_styles[map_id]; } else if( typeof EM.google_maps_styles !== 'undefined' ){ map_options.styles = EM.google_maps_styles; } jQuery(document).triggerHandler('em_maps_location_map_options', map_options); maps[map_id] = new google.maps.Map( document.getElementById('em-location-map-'+map_id), map_options); var marker_options = { position: em_LatLng, map: maps[map_id] }; jQuery(document).triggerHandler('em_maps_location_marker_options', marker_options); maps_markers[map_id] = new google.maps.Marker(marker_options); infoWindow = new google.maps.InfoWindow({ content: jQuery('#em-location-map-info-'+map_id+' .em-map-balloon').get(0) }); infoWindow.open(maps[map_id],maps_markers[map_id]); maps[map_id].panBy(40,-70); if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var pos = { lat: position.coords.latitude, lng: position.coords.longitude }; infoWindow.setPosition(pos); infoWindow.setContent('Location found.'); infoWindow.open(maps[map_id]); map.setCenter(pos); }, function() { handleLocationError(true, infoWindow, maps[map_id].getCenter()); }); } else { // Browser doesn't support Geolocation handleLocationError(false, infoWindow, maps[map_id].getCenter()); } function handleLocationError(browserHasGeolocation, infoWindow, pos) { infoWindow.setPosition(pos); infoWindow.setContent(browserHasGeolocation ? 'Error: The Geolocation service failed.' : 'Error: Your browser doesn\'t support geolocation.'); infoWindow.open(maps[map_id]); }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Global Map, position via GeoLocation (JavaScript(’ is closed to new replies.