Plugin Directory

Changeset 1566232


Ignore:
Timestamp:
01/02/2017 11:43:23 AM (9 years ago)
Author:
svrooij
Message:

Committing 0.0.3 to trunk

Location:
geocoded-posts/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • geocoded-posts/trunk/geocoded-posts.php

    r1566185 r1566232  
    1111 * Plugin URI:          https://github.com/svrooij/wp-geocoded-posts
    1212 * Description:         Widget with geocoded posts and editing geo location on a post.
    13  * Version:             0.0.2
     13 * Version:             0.0.3
    1414 * Author:              Stephan van Rooij
    1515 * Author URI:          https://svrooij.nl
     
    2626    *
    2727    */
    28   const VERSION = '0.0.1';
     28  const VERSION = '0.0.3';
    2929
    3030   /**
  • geocoded-posts/trunk/js/editor.js

    r1566185 r1566232  
    11// Javascript file for client side geocoding.
     2/* global WP_DYNAMIC, jQuery */
    23jQuery(document).ready(function ($) {
    34  // This button will appear when only the lat & long are filled in.
    45  $('#btn-fetch-locality').click(function (event) {
    56    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)
    1111      }
    12     )
    13 
    14     if(result) {
    15       $('#geocoded_posts_locality').val(result.formatted_address)
    16     }
     12    })
    1713  })
    1814
    1915  // 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) {
    2117    $(this).removeAttr('readonly')
    2218    $('#btn-fetch-locality').show()
     
    2824    var query = $('#geocoded_posts_locality').val()
    2925    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      })
    3633    }
    3734  })
    38 
    3935})
    4036
    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){
     37function queryGoogleMaps (queryArray, callback) {
    6038  // Set the server-side locale to ensure consistancy.
    6139  var requestData = {
     
    6947
    7048  // Add all the values from the initial query array.
    71   queryArray.forEach(function (value, index) {
     49  jQuery.each(queryArray, function (index, value) {
    7250    requestData[index] = value
    7351  })
     
    7553  // Load the data from Google maps.
    7654  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    }
    7759
    7860    // Find the result where the locality is in the types property.
     
    8365    // If we only found one result return it.
    8466    if (result.length === 1) {
    85       return result[0]
     67      callback(result[0])
    8668    }
    87 
    88     // return null otherwise.
    89     return null
    90   }
     69  })
    9170}
  • geocoded-posts/trunk/readme.txt

    r1566185 r1566232  
    55Requires at least: 4.4
    66Tested up to: 4.7
    7 Stable tag: 0.0.2
     7Stable tag: 0.0.3
    88License: MIT
    99License URI: https://raw.githubusercontent.com/svrooij/wp-geocoded-posts/master/LICENSE
     
    4747== Changelog ==
    4848
     49= 0.0.3 =
     50Serious bug in the client-side geocoding javascript file fixed.
     51
    4952= 0.0.2 =
    5053* Added server-side reverse geocoding (looking up the locality at a certain latitude longitude).
Note: See TracChangeset for help on using the changeset viewer.