Abhishek K Abhishek K - 1 year ago 103
Javascript Question

Reverse Geocoding in Javascript returns MissingKeyMap error

I am trying to get formatted address of customer who access my web page.

For that I wrote function to get lat long and then Reverse geocode it to formatted address.

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
function coordinates_to_address(lat, lng) {
var latlng = new google.maps.LatLng(lat, lng);
var geocoder= new google.maps.Geocoder();
geocoder.geocode({'latLng': latlng}, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
if(results[0]) {
} else {
alert('No results found');
} else {
var error = {
'ZERO_RESULTS': 'No address'

// alert('Geocoder failed due to: ' + status);
$('#address_new').html('<span class="color-red">' + error[status] + '</span>');

navigator.geolocation.getCurrentPosition(function(location) {
var lat= location.coords.latitude;
var long= location.coords.longitude
coordinates_to_address(lat, long);


The log showed the output lat long


But this function returned an error:

Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error
Line 34

Is there any easier method to get the formatted address of a lat long?

Answer Source
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download