Last active
December 7, 2017 15:06
-
-
Save guillaumebcom/08125bf7a2d640c9380e7ef4931415b6 to your computer and use it in GitHub Desktop.
Tumblr geo-tagging 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{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