I want my code working before I upgrade to latest ver of php and google maps API. So if ur comment is somin about old code or optimization I know some things have deprecated.
I have a form that somone fills out and it takes the form data and makes a marker using it. However im not sure how to pull the data from the form onto the marker window. The form data pulls fine with a phpmailer script, however I cant get the form data onto the map1 marker0 window.Can anyone help quide me to trasfer the form data onto the info window for the marker? I may have to redo code to place marker after the message is filled out
HERE IS A FIDDLE
https://jsfiddle.net/h9d2juyv/
<!DOCTYPE html>
<head>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map1 {
width:95%;
height:800px;
border: 3px solid blue;
margin: 0 auto;
}
#map2 {
width:95%;
height:800px;
border: 3px solid green;
margin: 0 auto;
}
#demo{ border: 2px solid yellow;
display:table;}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="SHORTCUT ICON" href="images/favicon.ico"/>
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<title>Fine Line Auto Body Shop | Collision Repair | Columbus Ohio.</title>
<meta name="description" content="Fine Line Auto Body Shop specializes in collision repair servicing all of Columbus Ohio. Call us today 1(614) 258-5555 for free estimate." />
<meta name="keywords" content="Body Shop, Columbus, Ohio, Auto Body Repair, Collision Repair, Free estimate, Columbus Ohio Central Ohio Collision Repair, Auto Body, Truck Body, Van Body, Columbus, Ohio Body Shop" />
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<link rel="stylesheet" href="css/flipcard.css" type="text/css" />
<link rel="stylesheet" href="css/style22.css" type="text/css" />
<script src="js/estimate.js"></script>
<script>
$(document).ready(function() {
$("#mobmenu_hidden").click(function(){
$("#navagation").toggle();
});
});
$(document).ready(function() {
$('#blah').removeClass('hidden');
var $animationElements = $('.animation-element');
var $window = $(window);
// ps: Let's FIRST disable triggering on small devices!
var isMobile = window.matchMedia("only screen and (max-width: 768px)");
if (isMobile.matches) {
$animationElements.removeClass('animation-element');
}
function checkIfInView() {
var windowHeight = $window.height();
var windowTopPosition = $window.scrollTop();
var windowBottomPosition = (windowTopPosition + windowHeight);
$.each($animationElements, function () {
var $element = $(this);
var elementHeight = $element.outerHeight();
var elementTopPosition = $element.offset().top;
var elementBottomPosition = (elementTopPosition + elementHeight);
//check to see if this current container is within viewport
if ((elementBottomPosition >= windowTopPosition) &&
(elementTopPosition <= windowBottomPosition)) {
$element.addClass('in-view');
} else {
$element.removeClass('in-view');
}
});
}
$window.on('scroll resize', checkIfInView);
$window.trigger('scroll');
/* @end viewport trigger script */
});
</script>
<!--------------------------------- MAP CRAP----------------------------------->
</head>
<script type="text/javascript">
$(document).ready(function() {
var $animationElements = $('.animation-element');
var $window = $(window);
// ps: Let's FIRST disable triggering on small devices!
var isMobile = window.matchMedia("only screen and (max-width: 768px)");
if (isMobile.matches) {
$animationElements.removeClass('animation-element');
}
function checkIfInView() {
t = $window.height();
var windowHeight = $window.height();
var windowTopPosition = $window.scrollTop();
var windowBottomPosition = (windowTopPosition + windowHeight);
$.each($animationElements, function () {
var $element = $(this);
var elementHeight = $element.outerHeight();
var elementTopPosition = $element.offset().top;
var elementBottomPosition = (elementTopPosition + elementHeight);
//check to see if this current container is within viewport
if ((elementBottomPosition >= windowTopPosition) &&
(elementTopPosition <= windowBottomPosition)) {
$element.addClass('in-view');
} else {
$element.removeClass('in-view');
}
});
}
$window.on('scroll resize', checkIfInView);
$window.trigger('scroll');
/* @end viewport trigger script */
});
</script>
<div class="testwrap">
<div class="sec2">
<div class="content2">
<div class="towright">
<div class="callout animation-element fadeinright">
<div class="bthead"><span class="mainHEader1">where is your vehicle?</span><br>
<hr class="redline">
<p><?php echo $content1; ?></p>
</div>
<div class="btloc">
<a href="#NoCredit">
<button href="#NoCredit" type="input" id="try" name="submi" class="button_text" value="">
<!--add this after value ""<?php echo $dis; ?>when u fix mobile location-->
<span id="boxcorner"></span>
<div class="right2_button"><?php echo $deviceType; ?></div>
</button>
</a>
</div>
<div class="bthr"><br>Or<br></div><br>
<div class="btaddy">
<a href="#NoCredit">
<!--when clicked changes text to cacel tow witch will show main test div and clear form fields---->
<button type="input" id="saveFor" name="submi" class="button_text" value="">
<span id="boxcorner"></span>
<div class="right2_button"><span id="offset">Enter</span> Address</div>
</button>
</a>
</div>
<br>
<div class="dtdis">Computers cannot use GPS correctly due do privacy laws and can only locate the server your connected too. </div>
<div class="callout animation-element fadeinleft">
</div><!--fadeinright-->
</div><!--fadeinright-->
</div><!--towright-->
<div class="towleft">
<div class="callout animation-element fadeinleft">
<div class="scene scene--card">
<div class='card'>
<div class="card__face card__face--front">
CLICK ENTER ADDY
</div>
<div class="card__face card__face--back">
<div class="bktest">
<form id="AUTO" method="post" action="" novalidate>
<h3>CONTACT INFO</h3>
<input type="hidden" class="dddfff" name="token" value="3308f582b5dbc12f99a823c77be6cdc8" />
<input type="hidden" class="dddfff" name="miles" value="" />
<div id="addy_holder">
<div class="upd">
<div id="upddd4">Customer information:</div>
</div>
<div class="staydog">
<div id="contact_name">Name: </div>
<input id="inputField" name="name" class="" size="15" maxlength="17" value="" type="text" placeholder="name">
</div><!--staydog-->
<div class="staydog">
<div id="contact_name">Email: *<span id="reqqq">Is Required</span></div>
<input type="email" id="emailinput" name="email" class="" maxlength="40" value="" placeholder="email" required/>
</div>
<div class="staydog">
<div id="contact_name">Phone: * <span id="req">Is Required</span></div>
<input type="tel" id="cinfo" name="phone" class="" maxlength="15" value="" placeholder="Home/Cell Phone" title="Phone Number Format:1(614) 000-0000"/>
</div>
</div><!--addyholder-->
<!--------------------- addy info ------------->
<div id="addy_holder">
<div class="upd">
<div id="upddd4">Location information:</div>
</div>
<div id="staydog9">
<div id="contact_name">Address: *</div>
<input type="text" id="location" name="address" class="" size="" maxlength="40" value="" placeholder="Address(PC users)">
</div><!--hide when in mobile-->
<div class="staydog">
<div id="contact_phone">Address2: *</div>
<input type="text" id="location2" name="address2" class="" maxlength="40" value="" placeholder="Apt, Suite, etc (optional)"/>
</div>
</div><!-- addy holder -->
<div id="addy_holder">
<div id="staydog8">
<div id="contact_phone">City:</div>
<input type="text" id="locality" name="city" class="" maxlength="50" value="" placeholder="City"/>
</div>
<div id="staydog7">
<div id="contact_name">State: </div>
<input type="text" id="administrative_area_level_1" name="state" class="half-input" maxlength="17" value="Ohio" placeholder="State/Province">
</div>
<div class="staydog" style="display:none;">
<div id="contact_name">Country: </div>
<input type="text" id="country" name="country" class="" maxlength="17" placeholder="Country"/>
</div>
<div id="staydog6">
<div id="contact_name">Zip:</div>
<input type="text" class="half-input" placeholder="Zip/Postal code" id="postal_code" name="zip" maxlength="5" />
</div>
</div><!-- addy holder -->
<div id="addy_holder22">
<div id="upddd4">Billing and Rental car:</div>
<div class="staydog22">
<select name="sloc" id="sloc">
<option value="Any">Billing Choice</option>
<option value="Central">one</option>
<option value="North">two</option>
</select>
</div><!--staydog-->
<div class="staydog22">
<section class="plan cf">
<div id="ftx1"><span class=""></span>insurance</div>
<input type="radio" name="maincov" id="yes" value="Yes"><label class="free-label four col" for="yes">Yes</label>
<input type="radio" name="maincov" id="Full Coverage" value="No" ><label class="basic-label four col" for="Full Coverage">No</label>
</section>
</div><!--staydog-->
</div><!-- addy holder -->
<div id="contact_message">MESSAGE:<br>
<textarea id="element_3" name="message" class="element textarea medium" placeholder="START TYPING MESAGE HERE..."></textarea>
</div>
<h4>THANK YOU!</h4>
<h5>Once you hit Submit a representative will be with you shortly.</h5>
<p id="demo">mob loc stats</p>
<div class="CxName" id="CxName">name</div>
<div id="map1"></div>
<div class="button_holder">
<input type="button" name="previous" class="previous action-button" value="Previous" />
</div>
<input type="" class="field" id="latitude" name="lat" placeholder="does lat copy?"></input>
<input type="hidden" class="field" id="longitude" name="lng" placeholder="does long copy?"></input>
</form>
</div><!--bktest-->
</div>
</div>
</div>
</div>
</div><!--towleft-->
</div>
</div>
<script>
//window.onload = initMap;
let today = new Date();
let yesterday = new Date();
let tommorrow = new Date();
//should be able to shorten and remove bottom 2 lines
yesterday.setDate(today.getDate() - 1);
tommorrow.setDate(today.getDate() + 1);
console.log('Yesterday: ' + yesterday);
console.log('Today: ' + today);
console.log('Tommorrow: ' + tommorrow);
"use strict";
function flip() {
$('.card').toggleClass('is-flipped');
//document.getElementById('saveFor').disabled = true;
//document.getElementById('try').disabled = true;
}
document.getElementById('saveFor').addEventListener('click', flip);
document.getElementById('try').addEventListener('click', flip);
document.getElementById('saveFor').addEventListener('click', initMap);
function initMap() {
window.alert('initMap ran');
document.getElementById('try').addEventListener('click', cnn);
const componentForm = [
'location',
'locality',
'administrative_area_level_1',
'country',
'postal_code',
];
const map1 = new google.maps.Map(document.getElementById("map1"), {
zoom: 11,
mapId: '744525hh',
center: {
lat: 38.998178,
lng: -82.998795
},
mapTypeControl: false,
fullscreenControl: true,
zoomControl: true,
streetViewControl: true
}); //map1
//add more markers this way
// const usrloc = new google.maps.Marker({
// map: map1,
// draggable: false,
// setZoom: 11,
// });
const marker0 = new google.maps.Marker({
map: map1,
draggable: false,
setZoom: 11,
icon: {
url: "https://maps.google.com/mapfiles/ms/icons/blue-dot.png"
}
});
const autocompleteInput = document.getElementById('location');
const autocomplete = new google.maps.places.Autocomplete(autocompleteInput, {
fields: ["address_components", "geometry", "name"],
types: ["address"],
});
//console.log(autocompleteInput.value);
autocomplete.addListener('place_changed', function() {
marker0.setVisible(true);
//add single markers this way usrloc.setVisible(true);
const place = autocomplete.getPlace();
//console.log(place.geometry.location);
if (!place.geometry) {
// User entered the name of a Place that was not suggested and
// pressed the Enter key, or the Place Details request failed.
window.alert('No details available for input: '' + place.name + ''');
return;
}
renderAddress(place);
fillInAddress(place);
});
function fillInAddress(place) { // optional parameter
// optional parameter
window.alert('fillInAddress fired');
const addressNameFormat = {
'street_number': 'short_name',
'route': 'long_name',
'locality': 'long_name',
'administrative_area_level_1': 'short_name',
'country': 'short_name',
'postal_code': 'short_name',
};
const getAddressComp = function(type) {
for (const component of place.address_components) {
if (component.types[0] === type) {
return component[addressNameFormat[type]];
}
}
return '';
};
document.getElementById('location').value = getAddressComp('street_number') + ' ' +
getAddressComp('route');
//auto complete adress filling form from filling out form
//document.getElementById("country").value = place.geometry.vicinity.short_name();
document.getElementById("latitude").value = place.geometry.location.lat();
document.getElementById("longitude").value = place.geometry.location.lng();
for (const component of componentForm) {
// Location field is handled separately above as it has different logic.
if (component !== 'location') {
document.getElementById(component).value = getAddressComp(component);
}
}
}
//when try byutton is pressd do this function
function cnn(ddd) {
//window.alert(' cnn was fired');
//hide threse when in mobile have to figure out
document.getElementById("staydog9").style.display = "none";
document.getElementById("staydog8").style.display = "none";
document.getElementById("staydog7").style.display = "none";
document.getElementById("staydog6").style.display = "none";
const x = document.getElementById("demo");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
// mobile button to get cords
function showPosition(ddd) {
window.alert('showPosition mob');
var lat = ddd.coords.latitude;
var lon = ddd.coords.longitude;
var latlon = new google.maps.LatLng(lat, lon);
//inserts lat/lon into form fields
document.getElementById("latitude").value = lat;
document.getElementById("longitude").value = lon;
console.log('|' + lat + '|', '|' + lon + '|'); // right click inspect and look at log empty by default.
//not needed atm save for usefullness
//x.innerHTML =
// "accu: " + ddd.coords.accuracy +
// "<br>Latitude: " + lat +
// "<br>Longitude: " + lon +
// "<br>both: " + latlon +
// "<br>time stamp: " + ddd.timestamp;
window.alert('does this even work');
var lat = ddd.coords.latitude;
var lon = ddd.coords.longitude;
var latlon = new google.maps.LatLng(lat, lon);
// makes the view fire one at a time instead of both at onces
//Mobile marker
marker0.setPosition(latlon); // SET MARKER POSTION.
map1.setCenter(latlon); // CENTER MAP.
marker0.setTitle('Mobile Location'); // mobile pick up location
map1.setZoom(14); //zoomz map to marker
marker0.setVisible(true); // SEE MAKER?.
marker0.setDraggable(false) //if true need listener to update cords
// confirm address or a div(needs styled)???.
}//showPosition(ddd)
}//cnn(ddd)
//PC marker
function renderAddress(place) {
//window.alert('renderAddress fired');
map1.setCenter(place.geometry.location); // CENTER MAP.
map1.setZoom(13); //zoomz map to marker
marker0.setPosition(place.geometry.location); // SET MARKER POSTION.
marker0.setVisible(true); // SEE MAKER?.
marker0.setTitle('PC Computer location');
marker0.setDraggable(false)
var place = autocomplete.getPlace();
var lat = place.geometry.location.lat();
var lng = place.geometry.location.lng();
console.log('lat:' + lat, 'lng:' + lng);
} //renderAddress
// Get the input field
var inputField = document.getElementById("inputField");
// Add event listener to detect input changes
inputField.addEventListener("input", function() {
// Get the value from the input field
var inputValue = inputField.value;
// Display the value
document.getElementById("CxName").innerText = inputValue;
});
//this is the div that both buttons use to display map info data
var location1 = '<div class="bui_hold1"><p id="output"></p>Verify Your Info.<br><div class="CxInfo"><div class="CxName" id="CxName">name</div><div class="CxPhone">phone</div><div class="CxEmail">email</div><div class="CxAddy">addy</div></div><div class="CarInfo"><div class="CxYear">year</div><div class="CxMake">make</div><div class="CxModel">model</div><div class="CxBill">bill</div><div class="CxRent">rent</div><div class="CxMess">message</div></div><input id="saveForm" class="button_text" type="submit" name="submit" value="Submit "/></div>';
var infoWindow1 = new google.maps.InfoWindow({
'content': location1,
});
marker0.addListener('click', function() {
infoWindow1.open(map1, marker0);
//console.log('this happened');
});
//open infowindow1 window by defult
infoWindow1.open(map1, marker0);
//closes info window when clicking on map
google.maps.event.addListener(map1, "click", function(event) {
infoWindow1.close();
});
//try to get this first marker to marker1
var markers = [
{
"title": 'place4',
"lat": '29.928669',
"lng": '-22.831665',
"manager": 'tom.',
"description": 'Brice Rd. is situated near Byculla station is famous as Mumbai (Bombay) Zoo.'
},
{
"title": 'place5',
"lat": '32.991079',
"lng": '-82.026252',
"manager": 'frank',
"description": 'OSU is a large protected area in the northern part of Mumbai city.'
},
{
"title": 'place1',
"lat": '20.062229',
"lng": '-22.994070',
"manager": 'bill',
"description": 'Morse rd is a large protected area in the northern part of Mumbai city.'
}
];
//Create and open InfoWindow.
var infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(map1, "click", function(event) {
infoWindow.close();
});
for (var i = 0; i < markers.length; i++) {
var data = markers[i];
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map1,
title: data.title
});
//Attach click event to the marker for buinees.
(function(markers, data) {
google.maps.event.addListener(marker, "click", function(e) {
//Wrap the content inside an HTML DIV in order to set height and width of InfoWindow.
infoWindow.setContent("<div class='bui_hold1'><div class='info_sec'><div class='bui_name'>" + data.title + "</div><!--bui_name--><div class='geo_info'><div class='geo_dis'>" + data.dis + "</div><!--data.dis--><div class='geo_time'>" + data.time + "</div><!--data.time--></div><!--geo_info--></div><!--info_sec--><!--first section--><div class='bui_info'><div class='dir_addy'>" + data.address + "</div><!--dir_btn--><div class='con_info'><div class='label'>Phone</div><!--pho_num--><div class='pho_num'><a href='tel:16142585555'>" + data.phone + "</a></div><!--pho_num--><div class='label'>Fax</div><!--pho_num--><div class='fax_num'>" + data.fax + "</div><!--fax_num--></div><!--con_info--><div class='dir_info'><div class='label'>Get Directions</div><!--pho_num--></div><!--bui_info--><!--second section--><div class='bui_pic'><div class='man_pic'></div><!--man_pic--><div class='man_name'>" + data.manager + "</div><!--man_name--></div><!--bui_pic--><div class='hidcord'><div class='geo_lat'>" + data.lat + "</div><div class='geo_long'>" + data.lng + "</div></div><!--hidcord--></div><!--bui_hold-->"
);
infoWindow.open(map1, markers);
map1.panTo(this.getPosition());
});
})
(marker, data);
}
} // ini map
</script>
</div><!--testwrap-->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBHkuLjYNbP0A8UrsqKIUR3itSuyjcz9pc&libraries=places&channel=GMPSB_addressselection_v1_cAB&loading=async"></script>
</body>
</html>