Presentation is loading. Please wait.

Presentation is loading. Please wait.

11 Using the Google Maps API. 2 Objectives You will be able to Use the Google Maps API to display a map of any location on an HTML page. Programatically.

Similar presentations


Presentation on theme: "11 Using the Google Maps API. 2 Objectives You will be able to Use the Google Maps API to display a map of any location on an HTML page. Programatically."— Presentation transcript:

1 11 Using the Google Maps API

2 2 Objectives You will be able to Use the Google Maps API to display a map of any location on an HTML page. Programatically modify the location and zoom level of the map.

3 33 The Google Maps API Permits web applications to use functionality of google maps. Tutorial: https://developers.google.com/maps/documentation/javascript/tutorial

4 4 Getting Started Create a new Empty Web Site in Visual Studio. Google_Maps_Demo.NET Framework 3.5 Add an HTML page. Map.html

5 55 Google Maps Tutorial Scroll down

6 6 Obtaining an API Key No longer necessary. Ignore for now. Scroll down to Hello, World

7 7 Hello World You can copy and paste from this page, but some modification is necessary.

8 8 html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"> function initialize() { var myOptions = { center: new google.maps.LatLng(-34.397, 150.644), zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); }

9

10 10 Map Options function initialize() { var myOptions = { center: new google.maps.LatLng(-34.397, 150.644), zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } How can we determine latitude and longitude of the place we want to map? http://www.tech-recipes.com/rx/2403/google_maps_get_latitude_longitude_values/

11 11 Search for Desired Location

12 12 Right click on the red "A" pin and select "What's here"

13 13 Lat-Long appears in the Address search bar. Copy and paste into script.

14 14 Set Lat-Long

15 15 Map with New Center Location Set zoom to 15

16 16 Adjust Zoom Level

17 17 Campus Map

18 Satellite Image

19 Zoom in More

20 20 Adding Our Own Stuff Let’s add text entry boxes to show and set the latitude and longitude. Latitude: Longitude: <input type="button" id="Set" value="Set" onclick="Set_Position();" name="btnSetPosition" />

21 21 Show New Position At end of function initialize(), still inside the function body : google.maps.event.addListener(map, "idle", function() { var center = map.getCenter().toString(); var latlong = center.split(","); var tbLat = document.getElementById("tbLat"); tbLat.value = latlong[0].substring(1,8); latitude = tbLat.value; var tbLong = document.getElementById("tbLong"); tbLong.value = latlong[1].substring(0,9); longitude = tbLong.value; });

22 22 Let the User Set the Position Add to the script below function initialize: function Set_Position() { var tbLat = document.getElementById("tbLat"); var tbLong = document.getElementById("tbLong"); latitude = tbLat.value; longitude = tbLong.value; map.setCenter( new google.maps.LatLng(latitude,longitude )); } Remove var from map = new google.maps.Map()

23 23 Lat-Long Displayed

24 24 Setting the Position Type lat-long into the text boxes Click “Set” Let’s look at Miami Latitude 25.77 Longitude -80.17

25 25 Miami

26 26 Find the Lat/Long of the Empire State Building Zoom out Move to NYC Zoom in Move to 5 th Ave and 34 th Street

27 27 Locate NYC

28 28 Zooming In

29 29 April 2009

30 30 Dec. 2009

31 31 April 2010

32 32 April 2011

33 The Empire State Building (April 2011)

34 The Empire State Building (July 2012)


Download ppt "11 Using the Google Maps API. 2 Objectives You will be able to Use the Google Maps API to display a map of any location on an HTML page. Programatically."

Similar presentations


Ads by Google