Created
March 22, 2012 14:12
-
-
Save mortenjust/2158563 to your computer and use it in GitHub Desktop.
suggest from google maps api in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | |
<title>JS Bin</title> | |
<!--[if IE]> | |
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
<style> | |
article, aside, figure, footer, header, hgroup, | |
menu, nav, section { display: block; } | |
</style> | |
<script> | |
// initiate the text field with suggest | |
// | |
$(function() { suggest(); }); | |
// suggest on the location | |
// https://developers.google.com/maps/documentation/places/autocomplete | |
function suggest(whichField) { | |
var input = document.getElementById(whichField); | |
var autocomplete = new google.maps.places.Autocomplete(input); | |
google.maps.event.addListener(autocomplete, 'place_changed', function() { | |
var place = autocomplete.getPlace(); | |
lat = place.geometry.location.lat(); | |
lng = place.geometry.location.lng(); | |
dis = 0.0005; | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<input type="text" id="location"/> | |
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment