Loceo official plugin for jQuery
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.md
example.html
jquery.loceo-1.0.1.js

README.md

#Loceo jQuery Plugin ##Usage The geodetic and geocoding-plugin for jQuery

The underlying REST API is located at https://loceo.se/documentation/postalcode.

###API-Key This API and plugin is free of charge for requests in the order of thousands per month. You can get current pricing and your own developer key at https://loceo.se.

##Methods ###Postalcode to city Enables you to resolve a postalcode to city. Returns a Geojson-feature with coordinates.

$('#postalcode_input').loceo('city', {key:null}, function(feature){
	$('#city_output').val('');
	if(feature!=null && feature.properties!=null && feature.properties.city!=null){
		$('#city_output').val(feature.properties.city);
	}
});

End-point: https://api.loceo.se/v1/geocoding/city

###City to postalcode Enables you to resolve a city to postalcodes. Notice you can get several hundred of postalcodes. Returns a Geojson-featureCollection with coordinates.

$('#city_input').loceo('postalcode', {key:null}, function(collection){
	$('#postalcode_output').val('');
	if(collection!=null && collection.features!=null && collection.features.length>0){
		$('#postalcode_output').val(collection.features[0].properties.postalcode);
	}
});

End-point: https://api.loceo.se/v1/geocoding/postalcode

##How to use

  1. Download this plugin and jQuery (or use a public CDN)

  2. Include jQuery and this plugin right before the </body>-tag.

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.loceo-1.0.1.js"></script>
  1. Initiate the desired plugin using the examples from above. Put this <script>-tag right before the </body>-tag (after code in step 2). Change #postalcode_input and #city_output to your desired html-elements. Optional: Change null to your developer-key.
<script type="text/javascript">
   $(document).ready(function(){
   	$('#postalcode_input').loceo('city', {key:null}, function(feature){
   		$('#city_output').val('');
   		if(feature!=null && feature.properties!=null && feature.properties.city!=null){
   			$('#city_output').val(feature.properties.city);
   		}
   	});
   });
</script>
  1. Satisfaction!

Not working? Study example.html, Tutorials:How_jQuery_Works and id-selector. Still not working? Check Loceos end-point in your browser.