Changeset 1566232
- Timestamp:
- 01/02/2017 11:43:23 AM (9 years ago)
- Location:
- geocoded-posts/trunk
- Files:
-
- 3 edited
-
geocoded-posts.php (modified) (2 diffs)
-
js/editor.js (modified) (5 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
geocoded-posts/trunk/geocoded-posts.php
r1566185 r1566232 11 11 * Plugin URI: https://github.com/svrooij/wp-geocoded-posts 12 12 * Description: Widget with geocoded posts and editing geo location on a post. 13 * Version: 0.0. 213 * Version: 0.0.3 14 14 * Author: Stephan van Rooij 15 15 * Author URI: https://svrooij.nl … … 26 26 * 27 27 */ 28 const VERSION = '0.0. 1';28 const VERSION = '0.0.3'; 29 29 30 30 /** -
geocoded-posts/trunk/js/editor.js
r1566185 r1566232 1 1 // Javascript file for client side geocoding. 2 /* global WP_DYNAMIC, jQuery */ 2 3 jQuery(document).ready(function ($) { 3 4 // This button will appear when only the lat & long are filled in. 4 5 $('#btn-fetch-locality').click(function (event) { 5 6 event.preventDefault() 6 var latlng = String.format('{0},{1}', $('#geocoded_posts_lat').val(), $('#geocoded_posts_long').val()) 7 var result = queryGoogleMaps( 8 { 9 latlng: latlng, 10 sensor: true 7 var latlng = $('#geocoded_posts_lat').val() + ',' + $('#geocoded_posts_long').val() 8 queryGoogleMaps({latlng: latlng, sensor: true}, function (result) { 9 if (result) { 10 $('#geocoded_posts_locality').val(result.formatted_address) 11 11 } 12 ) 13 14 if(result) { 15 $('#geocoded_posts_locality').val(result.formatted_address) 16 } 12 }) 17 13 }) 18 14 19 15 // Normally the locality is read-only, but if you double click you can override that. 20 $('#geocoded_posts_locality').dblclick(function ( ) {16 $('#geocoded_posts_locality').dblclick(function (event) { 21 17 $(this).removeAttr('readonly') 22 18 $('#btn-fetch-locality').show() … … 28 24 var query = $('#geocoded_posts_locality').val() 29 25 if (query !== '') { 30 var result = queryGoogleMaps({query: query, sensor: false}) 31 if(result){ 32 $('#geocoded_posts_locality').val(result.formatted_address) 33 $('#geocoded_posts_lat').val(result.geometry.location.lat) 34 $('#geocoded_posts_long').val(result.geometry.location.lng) 35 } 26 queryGoogleMaps({address: query, sensor: false}, function (result) { 27 if (result) { 28 $('#geocoded_posts_locality').val(result.formatted_address) 29 $('#geocoded_posts_lat').val(result.geometry.location.lat) 30 $('#geocoded_posts_long').val(result.geometry.location.lng) 31 } 32 }) 36 33 } 37 34 }) 38 39 35 }) 40 36 41 // Function from http://stackoverflow.com/a/2534828/639153 42 if (!String.format) { 43 String.format = function () { 44 for (var i = 0, args = arguments; i < args.length - 1; i++) { 45 args[0] = args[0].replace('{' + i + '}', args[i + 1]) 46 } 47 return args[0] 48 } 49 } 50 51 if (!String.prototype.format && String.format) { 52 String.prototype.format = function () { 53 var args = Array.prototype.slice.call(arguments).reverse() 54 args.push(this) 55 return String.format.apply(this, args.reverse()) 56 } 57 } 58 59 function queryGoogleMaps(queryArray){ 37 function queryGoogleMaps (queryArray, callback) { 60 38 // Set the server-side locale to ensure consistancy. 61 39 var requestData = { … … 69 47 70 48 // Add all the values from the initial query array. 71 queryArray.forEach(function (value, index) {49 jQuery.each(queryArray, function (index, value) { 72 50 requestData[index] = value 73 51 }) … … 75 53 // Load the data from Google maps. 76 54 jQuery.getJSON('https://maps.googleapis.com/maps/api/geocode/json', requestData, function (data, status, jqXHR) { 55 if (data.status !== 'OK') { 56 console.log(data) 57 return 58 } 77 59 78 60 // Find the result where the locality is in the types property. … … 83 65 // If we only found one result return it. 84 66 if (result.length === 1) { 85 return result[0]67 callback(result[0]) 86 68 } 87 88 // return null otherwise. 89 return null 90 } 69 }) 91 70 } -
geocoded-posts/trunk/readme.txt
r1566185 r1566232 5 5 Requires at least: 4.4 6 6 Tested up to: 4.7 7 Stable tag: 0.0. 27 Stable tag: 0.0.3 8 8 License: MIT 9 9 License URI: https://raw.githubusercontent.com/svrooij/wp-geocoded-posts/master/LICENSE … … 47 47 == Changelog == 48 48 49 = 0.0.3 = 50 Serious bug in the client-side geocoding javascript file fixed. 51 49 52 = 0.0.2 = 50 53 * Added server-side reverse geocoding (looking up the locality at a certain latitude longitude).
Note: See TracChangeset
for help on using the changeset viewer.