Skip to content

Instantly share code, notes, and snippets.

@guillaumebcom
Last active December 7, 2017 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillaumebcom/08125bf7a2d640c9380e7ef4931415b6 to your computer and use it in GitHub Desktop.
Save guillaumebcom/08125bf7a2d640c9380e7ef4931415b6 to your computer and use it in GitHub Desktop.
Tumblr geo-tagging 3
{block:HasTags}
<script type="text/javascript">
var tags = new Array();
{block:Tags}
tags.push({JSTag});
{/block:Tags}
$(document).ready(function(){
$("#post-{PostID}").data('tags', tags)
});
// find the address/location in the tags
var address;
jQuery.each(tags, function(){
var hit = this.match(/^map: (.+)/i);
if (hit) {
hit[1].replace(/[~\.;:-]/, ', '); // commas are not allowed in tumblr tags as they are the separator
address = hit[1];
}
});
// Geocoding
if (address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
// attach the coordinates to the post
$("#map-canvas").data('coords', results[0].geometry.location);
}
});
}
</script>
{/block:HasTags}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment