i have user submitted form location field. want call google geocoding api , latitude , longitude of location ensure location exists , send 3 pieces of data db.
geocoder = new google.maps.geocoder(); geocoder.geocode( { 'address': location}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { alert(results[0].geometry.location); } else { alert('geocode not successful following reason: ' + status); } }); the place can find code alert correct coordinates in collections posts.js file, causing server error:
exception while invoking method 'post' referenceerror: google not defined
the geocoding should done in add post page manager (client side only). because geocoding call asynchronous, wasn't getting response before posting db. moving db post inside success branch of geocode function fixed it.
geocoder = new google.maps.geocoder(); geocoder.geocode( { 'address': pin.location}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { pin.lat = results[0].geometry.location.lat(); pin.lng = results[0].geometry.location.lng(); meteor.call('post', pin, function(error, id){ if (error) return alert(error.reason); meteor.router.to('pinpage', pin); }); } else { alert('geocode not successful following reason: ' + status); } });
Comments
Post a Comment