1. https://developers.google.com/maps/documentation
On the above page, click on, under "Map SDKs", the "JS" button. Then on that page click on "using API keys". This gives the following script that must be included in every Google API Map instance you make. This goes in the html of the page you want the map(s) to go in:
we use our API key for josephkennethmorgan@gmail.com (see Google maps is not free below:
replace "YOUR_API_KEY" with the API key you will generate in the next step.
2. Getting the API Key.
Go to https://console.cloud.google.com/apis/ (you'll need a google account and when you are signed in to that account your account will display on this page). Our test uses josephkennethmorgan@gmail.com.
Click on "Enable APIS and Services" near top of page (Note NOT the menu item at left). On the page that opens click "Maps Javascript API" button on page.
You may need to "create a new project".
Click "Credentials" menu item at left. On the new page that comes up click "create credentials" near the TOP of the page. this should display the API key. Copy the API key into the script tag above. NOte you can "restrict' the API key, which will restrict to a certain domain name. For testing purposes, I haven't done this.
DO THIS STEP BEFORE STEP ABOVE "Click Credentials..."????? Google maps is not free, you will need to enable billing. Go to https://mapsplatform.google.com/pricing/, click "get started" button "then create billing account" and follow instructions. >>>>Use the new API key this process gives you and put it in script above>>>>>>>>>>>>>. This gives you a $300 free credit or 1month trial. After that Google maps will stop working if you don't go in and allow payment.
3. Create an html element to put the map into (e.g.) and give that element an id (also, optionally, a class:
!!!!!!!!!!!!!!!!JUMP TO STEP 13 TO GET BEST CODE. OTHER STEPS ARE REALLY FOR EDUCATIONAL PURPOSES ONLY!!!!!!!!!!!!!!!!!
4. Create a function that the above script is going to "call back". As you can see from the script above, that function must be called "initMap". Note, don't inclue "script" tags if iserting this code into a js file.
5. Using css, you must give the html element for the map a height and width, otherwise the map won't show. So, usin g the "ourMap" id we write into our css file:
#ourMap{
height: 700px;
width: 100%;
}
6. Set up a new map object by declearing the "map" variable which gives us access to various properties and functions/methods. The "Map" object (note captial) takes 2 arguments a) what html element id to put the map into (ours is "ourMap" as per step #4 above) b) the center and zoom. These are REQUIRED options for any map. "Zoom" refers to what zoom level the map should be at on page open and ceneter refers to what location the map should be at on page open. Our location is toronto, which uses latitude and longitude. Lat and long of any google map can be obtained by right clicking on any map in by going to maps.google.com. We use Toronto for this test.
We put our map options into an object (variable) called "options"
<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
7. Adding A Single Map Marker
8. Change the Single Map Marker icon. Just add in "icon:" and the icons source
9. Create a Single "Info Window" i.e. so when you click on the marker we get info about the place. See myInfoWindow constant below, also see the addEventListener for the window.
10. Create multiple markers for different locations
11. Create multiple markers for different locations AND add separate icons for each location
12. Create multiple markers for different locations AND add separate icons for each location AND have different info windows for each location (popup info on hover or click)
13. Create multiple markers for different locations AND add separate icons for each location AND have different info windows for each location (popup info on hover or click) BUT WITH USING AN ARRAY TO KEEP CODE CLEANER. Note that I'm not completely sure how this all works.