Get path using the user’s location to the predefined marker (javascript google-mapsv3)

Asked

Viewed 38 times

0

I am using the answer that is in the question of the following link: question

And I don’t understand what I need to put on the line below where the comment is:

map = new google.maps.Map( /*creates Map variable*/ document.getElementById("map"), mapOptions /*Creates a new map using the passed optional parameters in the mapOptions parameter.*/);

1 answer

1


document.getElementById("map")

In this part of the code you put the id of the div where the map will be made, in this example the id of the div is "map". You can replace it with the id of your div.

mapOptions 

This is an object with the map options you will create, will pass the object you previously created in the example

var mapOptions = //Sets map options
 {
   zoom: 15,  //Sets zoom level (0-21)
   center: coords, //zoom in on users location
   mapTypeControl: true, //allows you to select map type eg. map or satellite
   navigationControlOptions:
   {
     style: google.maps.NavigationControlStyle.SMALL //sets map controls size eg. zoom
   },
   mapTypeId: google.maps.MapTypeId.ROADMAP //sets type of map Options:ROADMAP, SATELLITE, HYBRID, TERRIAN
 };

In this case you are setting the zoom, center and other settings on your map. Without the comments would just be:

map = new google.maps.Map(document.getElementById("map"), mapOptions);

The example is only commenting on what is each information. Just need to pass the correct div and the object with the settings you need.

  • Thank you very much for the answer however on this line I am having the following error: js:1 Uncaught Typeerror: Cannot read Property 'offsetWidth' of null_.Kf @js:1qg @js:1(Anonymous Function) @ VM71:39 . The error was taken from the browser console

  • 1

    Is your div id correct? is the same as in getElementById?

  • I really had Div’s name wrong. You solved my problem. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.