happy31 Posted February 13, 2015 Share Posted February 13, 2015 Hi, how can insert the " IP address geocodding" API in our project? Link to comment Share on other sites More sharing options...
happy31 Posted February 17, 2015 Author Share Posted February 17, 2015 please suggest me Link to comment Share on other sites More sharing options...
El Patron Posted February 17, 2015 Share Posted February 17, 2015 Can you provide more details of what you are trying to achieve? Now it's not exactly clear. 1 Link to comment Share on other sites More sharing options...
happy31 Posted February 17, 2015 Author Share Posted February 17, 2015 (edited) yes, we can design a website, only When the new user come in the website Then the user's location can display automatically? Edited February 17, 2015 by happy31 (see edit history) Link to comment Share on other sites More sharing options...
El Patron Posted February 17, 2015 Share Posted February 17, 2015 that is not supported by native PrestaShop. You would need to make custom changes. If you cannot make these changes yourself, then you can post in job offers section. Link to comment Share on other sites More sharing options...
happy31 Posted February 17, 2015 Author Share Posted February 17, 2015 the script file is like this: function GEOprocess(position) { document.getElementById('geo').innerHTML = 'Latitude: ' + position.coords.latitude + ' Longitude: ' + position.coords.longitude; GEOajax("geo.php?accuracy=" + position.coords.accuracy + "&latlng=" + position.coords.latitude + "," + position.coords.longitude +"&altitude="+position.coords.altitude+"&altitude_accuracy="+position.coords.altitudeAccuracy+"&heading="+position.coords.heading+"&speed="+position.coords.speed+""); } function GEOdeclined(error) { document.getElementById('geo').innerHTML = 'Error: ' + error.message; } if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(GEOprocess, GEOdeclined); }else{ document.getElementById('geo').innerHTML = 'Your browser sucks. Upgrade it.'; } if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); }else if(window.ActiveXObject){ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } geolocation lookup function GEOajax(url) { xmlHttp.open("GET", url, true); xmlHttp.onreadystatechange = updatePage; xmlHttp.send(null); } // this reads the response from the php script and updates the page with it's output function updatePage() { if (xmlHttp.readyState == 4) { var response = xmlHttp.responseText; document.getElementById("geo").innerHTML = '' + response; } } and the php file is like this: <?php $geo = 'http://maps.google.com/maps/api/geocode/xml?latlng='.htmlentities(htmlspecialchars(strip_tags($_GET['latlng']))).'&sensor=true'; $xml = simplexml_load_file($geo); foreach($xml->result->address_component as $component){ if($component->type=='street_address'){ $geodata['precise_address'] = $component->long_name; } if($component->type=='locality'){ $geodata['town_city'] = $component->long_name; } if($component->type=='country'){ $geodata['country'] = $component->long_name; } } list($lat,$long) = explode(',',htmlentities(htmlspecialchars(strip_tags($_GET['latlng'])))); foreach($geodata as $name => $value){ echo ''.$name.': '.str_replace('&','&',$value).'<br />'; } ?> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now