Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var markersArray = [];
- function addMarker(location) {
- marker = new google.maps.Marker({
- position: location,
- map: map
- });
- markersArray.push(marker);
- }
- function deleteOverlays() {
- if (markersArray) {
- for (i in markersArray) {
- markersArray[i].setMap(null);
- }
- markersArray.length = 0;
- }
- }
- var map = new google.maps.Map( document.getElementById("map_canvas"), {
- center: new google.maps.LatLng(47.997337,7.841653),
- zoom: 5,
- mapTypeId: google.maps.MapTypeId.ROADMAP,
- panControl: false,
- streetViewControl: false,
- mapTypeControl: false
- });
- var temp_address = $('input[name=input_location]').val();
- var temp_coords = $('input[name=input_coordinates]').val();
- $('input[name=other_address]').change(function() {
- if($('input[name=input_location]').val()){
- $('input[name=input_location]').val('');
- $('input[name=input_coordinates]').val('');
- }else{
- $('input[name=input_location]').val(temp_address);
- $('input[name=input_coordinates]').val(temp_coords);
- }
- });
- var geocoder = new google.maps.Geocoder();
- geocoder.geocode({
- address : $('input[name=input_location]').val(),
- region: 'no'
- }, function(results, status) {
- if (status.toLowerCase() == 'ok') {
- var coords = new google.maps.LatLng(
- results[0]['geometry']['location'].lat(),
- results[0]['geometry']['location'].lng()
- );
- map.setCenter(coords);
- map.setZoom(14);
- addMarker(coords);
- $('input[name=input_coordinates]').val( coords.lat() + ', ' + coords.lng() );
- $('input[name=other_address]').change(function(){
- if($('input[name=other_address]').is(':checked')){
- deleteOverlays();
- map.setZoom(5);
- }else {
- map.setCenter(coords);
- map.setZoom(14);
- addMarker(coords);
- }
- });
- }
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment