Created
July 17, 2015 23:54
-
-
Save aarongirard/f6762646f83965d5e816 to your computer and use it in GitHub Desktop.
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
| //global variables //google map | |
| var map; | |
| var marker; | |
| var currentMakerli; | |
| function initialize() { | |
| //set latlng of starting window of map | |
| var mapOptions = { | |
| center: { lat: 34.073609, lng: -118.562313}, | |
| zoom: 14, | |
| }; | |
| //set map using above options and attach to given element | |
| map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); | |
| //construct new marker; constructor takes an object with position and title properties | |
| //get lat long for marker | |
| var latlng = new google.maps.LatLng(34.073514, -118.562348); | |
| marker = new google.maps.Marker({ | |
| position: latlng, | |
| map: map, | |
| title: "Home" | |
| }); | |
| //on button click | |
| //if button is marked then unmark (r) | |
| //an elemtn, when clicked, needs to send a position and title and whatever else to a function to create a marker, this | |
| //marked then would be added to an array "marked", which would store all the marked values. | |
| //maybe create a wrapper for the maker that also includes a ms time which can be used as a unique key to | |
| } | |
| //set map | |
| google.maps.event.addDomListener(window, 'load', initialize); | |
| //on click of li | |
| $(".DataList li").click(function(){ | |
| //if current marker set to this already | |
| //remove marker | |
| if ( $(this).attr('id') === 'current') { | |
| marker.setMap(null); | |
| $(this).attr('id', ''); | |
| } else { | |
| $(this).attr('id','current'); | |
| var latlngarr = getLatLngFromString($(this).attr('data-position')); | |
| var lat = latlngarr[0]; | |
| var lng = latlngarr[1]; | |
| thisLatlng = new google.maps.LatLng(lat,lng); | |
| var marker = new google.maps.Marker({ | |
| position: latlng, | |
| map: map, | |
| google.maps.event.addDomListener(window, 'load', initialize); | |
| }); | |
| //marker.setMap(map); | |
| } | |
| }); | |
| function getLatLngFromString(string){ | |
| var array = string.split(','); | |
| array[0] = parseFloat(array[0]); | |
| array[1] = parseFloat(array[1]); | |
| return array; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment