Note that there are some explanatory texts on larger screens.

plurals
  1. POGeonames get latitude and longtitude
    primarykey
    data
    text
    <p>I have been coding around with Google Geocoding until I found out that the Geocoding API may only be used in conjunction with a Google map. That is unconvinient because I don't need to display a map. So I switched to Geonames which is awesome! </p> <p>I get the latitude and longitude of an address and add them to my database.</p> <p>The code below is Jquery for a text input where users add their city/town and an auto-complete appears presuming the city they are typing. It works great but I also want to add the latitude and longitude of their city in 2 hidden form fields for sending to the database.</p> <p>How is it possible to retrieve those coordinates from Geonames?</p> <pre><code>$(function() { function log( message ) { $( "&lt;div/&gt;" ).text( message ).prependTo( "#log" ); $( "#log" ).attr( "scrollTop", 0 ); } $( "#city" ).autocomplete({ source: function( request, response ) { $.ajax({ url: "http://ws.geonames.org/searchJSON", dataType: "jsonp", data: { featureClass: "P", style: "full", maxRows: 12, name_startsWith: request.term }, success: function( data ) { response( $.map( data.geonames, function( item ) { return { label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName, value: item.name } })); } }); }, minLength: 2, select: function( event, ui ) { log( ui.item ? "Selected: " + ui.item.label : "Nothing selected, input was " + this.value); }, open: function() { $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" ); }, close: function() { $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" ); } }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload