javascript - Returning Zipcode from Geolocation in Meteor -
<template name="home"> <a href="#" id="showmylocation">where i</a> <div id="location">postal address</div> <div id="zipcode">zip code</div> </template>
i'm trying retrieve user's current address , zipcode using geolocation in meteor. or advice appreciated.
this javascript
meteor.startup(function() { googlemaps.load(); }); template.home.events({ 'click #showmylocation': function(event){ event.preventdefault(); $(this).html('determining address...'); navigator.geolocation.getcurrentposition(function (position){ var geocoder = new google.maps.geocoder(); var latlng = new google.maps.latlng(position.coords.latitude, position.coords.longitude); geocoder.geocode({ 'latlng': latlng}, function (results, status){ (var = 0; < results[0].address_components.length; i++) { var address = results[0].address_components[i]; if (address.types[0] == "postal_code"){ $('#zipcode').html(address.long_name); $('#location').html(results[0].formatted_address); $('#showmylocation').hide(); } } }); }); return false; } });
what want called reverse geocoding. heres how can google maps javascript api https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse
you can use geonames api that.
Comments
Post a Comment