Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect HTML5 Geolocation Support Using PHP

I need to detect HTML5 Geolocation support using PHP so that I can load a backup JavaScript that supports Geolocation using IP Address.

How to do this with or without PHP.

like image 779
Aayush Avatar asked Feb 26 '23 17:02

Aayush


1 Answers

Have you considered using Modernizr to detect the HTML5 support? This isn't PHP specific since it's done in JavaScript but you can use this snippet to load your backup file:

if (Modernizr.geolocation){
   // Access using HTML5
   navigator.geolocation.getCurrentPosition(function(position) { ... });
}else{
   // Load backup file
   var script = document.createElement('script');
   script.src = '/path/to/your/script.js';
   script.type = 'text/javascript';
   var head = document.getElementsByTagName("head")[0];
   head.appendChild(script);
}

(Based on http://www.modernizr.com/docs/#geolocation)

like image 72
Jonathon Bolster Avatar answered Mar 07 '23 23:03

Jonathon Bolster