{"id":5402,"date":"2024-06-07T00:49:45","date_gmt":"2024-06-07T00:49:45","guid":{"rendered":"https:\/\/play.exploragame.com.ar\/?page_id=5402"},"modified":"2024-06-07T01:11:11","modified_gmt":"2024-06-07T01:11:11","slug":"mapa-google-con-localizacion","status":"publish","type":"page","link":"https:\/\/play.exploragame.com.ar\/index.php\/mapa-google-con-localizacion\/","title":{"rendered":"mapa google con localizacion"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"5402\" class=\"elementor elementor-5402\" data-elementor-post-type=\"page\">\n\t\t\t\t<div class=\"elementor-element elementor-element-6207d46 e-flex e-con-boxed e-con e-parent\" data-id=\"6207d46\" data-element_type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-cd6cd13 elementor-widget elementor-widget-html\" data-id=\"cd6cd13\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n    <meta charset=\"UTF-8\">\r\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n    <title>Geolocation Redirect<\/title>\r\n    <style>\r\n        #map {\r\n            height: 100vh;\r\n            width: 100%;\r\n        }\r\n        .button-container {\r\n            position: absolute;\r\n            top: 10px;\r\n            left: 50%;\r\n            transform: translateX(-50%);\r\n            z-index: 5;\r\n            background-color: white;\r\n            padding: 10px;\r\n            border-radius: 5px;\r\n            box-shadow: 0 2px 6px rgba(0,0,0,0.3);\r\n        }\r\n    <\/style>\r\n<\/head>\r\n<body>\r\n    <div id=\"map\"><\/div>\r\n    <div class=\"button-container\">\r\n        <button onclick=\"locateUser()\">Centrar en mi ubicaci\u00f3n<\/button>\r\n    <\/div>\r\n    <script>\r\n        let map, userMarker;\r\n\r\n        function initMap() {\r\n            \/\/ Create a map centered at a default location\r\n            map = new google.maps.Map(document.getElementById('map'), {\r\n                zoom: 15,\r\n                center: { lat: -34.397, lng: 150.644 },\r\n                mapTypeId: 'roadmap'\r\n            });\r\n\r\n            \/\/ Define the target location and radius\r\n            const targetLocation = { lat: 40.748817, lng: -73.985428 }; \/\/ Replace with your target coordinates\r\n            const targetRadius = 20; \/\/ Radius in meters\r\n\r\n            \/\/ Marker for the target location\r\n            const targetMarker = new google.maps.Marker({\r\n                position: targetLocation,\r\n                map: map,\r\n                title: 'Target Location'\r\n            });\r\n\r\n            \/\/ Try HTML5 geolocation\r\n            if (navigator.geolocation) {\r\n                navigator.geolocation.watchPosition(\r\n                    (position) => {\r\n                        const userLocation = {\r\n                            lat: position.coords.latitude,\r\n                            lng: position.coords.longitude\r\n                        };\r\n\r\n                        \/\/ If the userMarker already exists, just update its position\r\n                        if (userMarker) {\r\n                            userMarker.setPosition(userLocation);\r\n                        } else {\r\n                            \/\/ Marker for the user's location\r\n                            userMarker = new google.maps.Marker({\r\n                                position: userLocation,\r\n                                map: map,\r\n                                title: 'Your Location'\r\n                            });\r\n                        }\r\n\r\n                        \/\/ Calculate the distance between the user's location and the target location\r\n                        const distance = google.maps.geometry.spherical.computeDistanceBetween(\r\n                            new google.maps.LatLng(userLocation),\r\n                            new google.maps.LatLng(targetLocation)\r\n                        );\r\n\r\n                        \/\/ Check if the user is within the target radius\r\n                        if (distance <= targetRadius) {\r\n                            window.location.href = 'https:\/\/example.com'; \/\/ Replace with your target URL\r\n                        }\r\n                    },\r\n                    () => {\r\n                        handleLocationError(true, map.getCenter());\r\n                    }\r\n                );\r\n            } else {\r\n                \/\/ Browser doesn't support Geolocation\r\n                handleLocationError(false, map.getCenter());\r\n            }\r\n        }\r\n\r\n        function handleLocationError(browserHasGeolocation, pos) {\r\n            console.error(\r\n                browserHasGeolocation\r\n                    ? 'Error: The Geolocation service failed.'\r\n                    : 'Error: Your browser doesn\\'t support geolocation.'\r\n            );\r\n        }\r\n\r\n        function locateUser() {\r\n            if (navigator.geolocation) {\r\n                navigator.geolocation.getCurrentPosition(\r\n                    (position) => {\r\n                        const userLocation = {\r\n                            lat: position.coords.latitude,\r\n                            lng: position.coords.longitude\r\n                        };\r\n\r\n                        map.setCenter(userLocation);\r\n\r\n                        \/\/ If the userMarker already exists, just update its position\r\n                        if (userMarker) {\r\n                            userMarker.setPosition(userLocation);\r\n                        } else {\r\n                            \/\/ Marker for the user's location\r\n                            userMarker = new google.maps.Marker({\r\n                                position: userLocation,\r\n                                map: map,\r\n                                title: 'Your Location'\r\n                            });\r\n                        }\r\n                    },\r\n                    () => {\r\n                        handleLocationError(true, map.getCenter());\r\n                    }\r\n                );\r\n            } else {\r\n                \/\/ Browser doesn't support Geolocation\r\n                handleLocationError(false, map.getCenter());\r\n            }\r\n        }\r\n    <\/script>\r\n    <script async defer src=\"https:\/\/maps.googleapis.com\/maps\/api\/js?key=YOUR_API_KEY&callback=initMap&libraries=geometry\"><\/script>\r\n<\/body>\r\n<\/html>\r\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Geolocation Redirect Centrar en mi ubicaci\u00f3n<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"wf_page_folders":[],"class_list":["post-5402","page","type-page","status-publish"],"_links":{"self":[{"href":"https:\/\/play.exploragame.com.ar\/index.php\/wp-json\/wp\/v2\/pages\/5402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/play.exploragame.com.ar\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/play.exploragame.com.ar\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/play.exploragame.com.ar\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/play.exploragame.com.ar\/index.php\/wp-json\/wp\/v2\/comments?post=5402"}],"version-history":[{"count":10,"href":"https:\/\/play.exploragame.com.ar\/index.php\/wp-json\/wp\/v2\/pages\/5402\/revisions"}],"predecessor-version":[{"id":5412,"href":"https:\/\/play.exploragame.com.ar\/index.php\/wp-json\/wp\/v2\/pages\/5402\/revisions\/5412"}],"wp:attachment":[{"href":"https:\/\/play.exploragame.com.ar\/index.php\/wp-json\/wp\/v2\/media?parent=5402"}],"wp:term":[{"taxonomy":"wf_page_folders","embeddable":true,"href":"https:\/\/play.exploragame.com.ar\/index.php\/wp-json\/wp\/v2\/wf_page_folders?post=5402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}