var placeSearch, autocomplete;
var componentForm = {
street_number: 'short_name',
route: 'long_name',
locality: 'long_name',
administrative_area_level_1: 'short_name',
country: 'long_name',
postal_code: 'short_name'
};
var map;
var marker;
function initAutocomplete() {
var mapCanvas = document.getElementById("map");
var myCenter = new google.maps.LatLng(62, -110.0);
var mapOptions = {
center: myCenter,
zoom: 3
};
map = new google.maps.Map(mapCanvas, mapOptions);
marker = new google.maps.Marker({
position: myCenter,
animation: google.maps.Animation.BOUNCE
});
google.maps.event.addListener(marker, 'click', function() {
map.setZoom(2 * mapOptions.zoom);
map.setCenter(marker.getPosition());
});
marker.setMap(map);
google.maps.event.addListener(map, "click", function(e) {
//lat and lng is available in e object
placeMarker(map, e.latLng);
// var latLng = e.latLng;
// console.log("lat" + latLng.lat() + "long" + latLng.lng());
});
function placeMarker(map, location) {
marker.setPosition(location);
var infowindow = new google.maps.InfoWindow({
content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng()
});
infowindow.open(map, marker);
}
// Create the autocomplete object, restricting the search to geographical
// location types.
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */
(document.getElementById('autocomplete')), {
types: ['geocode']
});
// When the user selects an address from the dropdown, populate the address
// fields in the form.
autocomplete.addListener('place_changed', fillInAddress);
}
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
if (marker && marker.setMap)
marker.setMap(null);
marker = new google.maps.Marker({
position:...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.