Skip to content

Commit

Permalink
Improve browser share geolocation accuracy and better design
Browse files Browse the repository at this point in the history
  • Loading branch information
jloguercio committed May 27, 2016
1 parent 9a6dd12 commit 0c8ccba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
32 changes: 25 additions & 7 deletions main/auth/inscription.php
Expand Up @@ -50,17 +50,27 @@
function myLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geoPosition = function(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var latLng = new google.maps.LatLng(lat, lng);
initializeGeo(false, latLng)
});
};
var geoError = function(error) {
alert("Geocode '.get_lang('Error').': " + error);
};
var geoOptions = {
enableHighAccuracy: true
};
navigator.geolocation.getCurrentPosition(geoPosition, geoError, geoOptions);
}
}
function initializeGeo(address, latLng) {
geocoder = new google.maps.Geocoder();
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-75.503, 22.921);
var myOptions = {
zoom: 15,
Expand All @@ -82,8 +92,9 @@ function initializeGeo(address, latLng) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);
console.log(results[0]);
$("#address").val(results[0].formatted_address);
if (!address) {
$("#address").val(results[0].formatted_address);
}
var infowindow = new google.maps.InfoWindow({
content: "<b>" + $("#address").val() + "</b>",
size: new google.maps.Size(150, 50)
Expand Down Expand Up @@ -249,8 +260,15 @@ function initializeGeo(address, latLng) {
// Geolocation
if (in_array('address', $allowedFields)) {
$form->addElement('text', 'address', get_lang('AddressField'), ['id' => 'address']);
$form->addButton('geolocalization', get_lang('geolocalization'), 'globe', 'default', 'default', 'null', ['id' => 'geolocalization']);
$form->addButton('myLocation', get_lang('MyLocation'), 'map-marker', 'default', 'default', 'null', ['id' => 'myLocation']);
$form->addHtml('
<div class="form-group">
<label for="geolocalization" class="col-sm-2 control-label"></label>
<div class="col-sm-8">
<button class="null btn btn-default " id="geolocalization" name="geolocalization" type="submit"><em class="fa fa-map-marker"></em> '.get_lang('Geolocalization').'</button>
<button class="null btn btn-default " id="myLocation" name="myLocation" type="submit"><em class="fa fa-crosshairs"></em> '.get_lang('MyLocation').'</button>
</div>
</div>
');

$form->addHtml('
<div class="form-group">
Expand Down
35 changes: 25 additions & 10 deletions main/auth/profile.php
Expand Up @@ -39,9 +39,6 @@
var $image = $("#previewImage");
var $input = $("[name=\'cropResult\']");
var $cropButton = $("#cropButton");
var canvas = "";
var imageWidth = "";
var imageHeight = "";
$("input:file").change(function() {
var oFReader = new FileReader();
Expand Down Expand Up @@ -168,17 +165,27 @@ function show_icon_edit(element_html) {
function myLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geoPosition = function(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var latLng = new google.maps.LatLng(lat, lng);
initializeGeo(false, latLng)
});
};
var geoError = function(error) {
alert("Geocode '.get_lang('Error').': " + error);
};
var geoOptions = {
enableHighAccuracy: true
};
navigator.geolocation.getCurrentPosition(geoPosition, geoError, geoOptions);
}
}
function initializeGeo(address, latLng) {
geocoder = new google.maps.Geocoder();
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 15,
Expand All @@ -200,8 +207,9 @@ function initializeGeo(address, latLng) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
map.setCenter(results[0].geometry.location);
console.log(results[0]);
$("#address").val(results[0].formatted_address);
if (!address) {
$("#address").val(results[0].formatted_address);
}
var infowindow = new google.maps.InfoWindow({
content: "<b>" + $("#address").val() + "</b>",
size: new google.maps.Size(150, 50)
Expand Down Expand Up @@ -332,8 +340,15 @@ function initializeGeo(address, latLng) {

// Geolocation
$form->addElement('text', 'address', get_lang('AddressField'), ['id' => 'address']);
$form->addButton('geolocalization', get_lang('geolocalization'), 'globe', 'default', 'default', 'null', ['id' => 'geolocalization']);
$form->addButton('myLocation', get_lang('MyLocation'), 'map-marker', 'default', 'default', 'null', ['id' => 'myLocation']);
$form->addHtml('
<div class="form-group">
<label for="geolocalization" class="col-sm-2 control-label"></label>
<div class="col-sm-8">
<button class="null btn btn-default " id="geolocalization" name="geolocalization" type="submit"><em class="fa fa-map-marker"></em> '.get_lang('Geolocalization').'</button>
<button class="null btn btn-default " id="myLocation" name="myLocation" type="submit"><em class="fa fa-crosshairs"></em> '.get_lang('MyLocation').'</button>
</div>
</div>
');

$form->addHtml('
<div class="form-group">
Expand Down

0 comments on commit 0c8ccba

Please sign in to comment.