Skip to content

Commit

Permalink
Place tag detection and replacing "-" with "" (#2734)
Browse files Browse the repository at this point in the history
* Place tag detection and replacing "-" with ""

* Javascript changed

* Geocode method added

* Tweaks

* Tweaks

* Tweaks

* Tweaks 2

* Tweaks 3

* Update Gemfile.lock

* Climate fix

* add geocoded tags

* Tweaks

* Block shift and callback to onComplete

* onComplete binded with ajax

* place in starting of tag detection

* Tweaks
  • Loading branch information
mridulnagpal authored and jywarren committed Jun 5, 2018
1 parent 539229b commit 21bf91c
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions app/assets/javascripts/tagging.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
function addTag(tagname, selector) {

selector = selector || '#tagform';
if (tagname.slice(0,5).toLowerCase() === "place") {
place = tagname.split(":")[1];
place.replace("-", " ");
geo = geocodeStringAndPan(place);
}
else {
var el = $(selector);

var el = $(selector);

el.find('.tag-input').val(tagname);
el.find('.tag-input').val(tagname);

el.submit();
el.submit();
}

}

Expand Down Expand Up @@ -80,3 +86,27 @@ function initTagForm(deletion_path, selector) {
return el;

}

function geocodeStringAndPan(string, onComplete) {
var url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + string.split(" ").join("+");
var Blurred = $.ajax({
async: false,
url: url,
complete: function(data) {
geometry = data.responseJSON.results[0].geometry.location;
lat = geometry.lat;
lng = geometry.lng;

var geo = [lat, lng];

if (geo.length > 0) {
var r = confirm("This looks like a location. Is this full description of the location accurate?");
console.log(geo[0]);
console.log(geo[1]);
if(r) {
addTag("lat:" + geo[0].toString() + ",lng:" + geo[1].toString()+",place:"+string);
}
}
},
});
}

0 comments on commit 21bf91c

Please sign in to comment.