Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8153507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:02:26+00:00 2026-06-06T16:02:26+00:00

I am having issues getting setCenter to work. My JS console tells me: myMap

  • 0

I am having issues getting setCenter to work. My JS console tells me:

myMap is not defined

myMap.setCenter(newLatLng);

It is clearly defined in the historyMap() function

My JavaScript

44     function historyMap() {
45         var travelCoords = new Array();
46         var allCoords = new Array();
47         var myOptions = {
48                 center: new google.maps.LatLng(<?php echo $places[$lastPlace]['lat']; ?>, <?php echo $places[$lastPlace]['long']; ?>),
49                 zoom: 8,
50                 mapTypeId: google.maps.MapTypeId.HYBRID
51         };
52         var myMap = new google.maps.Map(document.getElementById("map"), myOptions);
53         allCoords = [
54         <?php for($i = 0; $i < $numPlaces; $i++) { ?>
55                 new google.maps.LatLng(<?php echo $places[$i]['lat']; ?>, <?php echo $places[$i]['long'];?>),
56         <?php } ?>
57         ];
58         var travelPath = new google.maps.Polyline({
59                 path: allCoords,
60                 strokeColor: "#FF0000",
61                 strokeOpacity: 1.0,
62                 strokeWeight: 4
63         });
64         lastLatLng = new google.maps.LatLng(<?php echo $places[$lastPlace]   ['lat'];?>, <?php echo $places[$lastPlace]['long'];?>);
65         var marker = new google.maps.Marker({
66                 icon: 'img/<?php echo $icon; ?>',
67                 position: lastLatLng,
68                 map: myMap,
69                 title: '<?php echo $places[$numPlaces-1]['title'];?>'
70         });
71         travelPath.setMap(myMap);
72     }
73
74     function setMapCenter(lat,lng) {
75
76         var newLatLng = new google.maps.LatLng(lat,lng);
77         myMap.setCenter(newLatLng);
78
79     }
80
81     $(function() {
82         historyMap();
83     });

The HTML calling the setMapCenter function:

<td><a href="javascript:void(0);" onClick="setMapCenter('49.261226','-123.113927')">Vancouver</a></td>

I really appreciate any insight anybody can provide.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:02:28+00:00Added an answer on June 6, 2026 at 4:02 pm

    It’s because your variable myMap is a local variable : it is only defined for your function historyMap().

    Initialize it, out your functions :

    var myMap = {};
    function historyMap() { ... }
    // other functions
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having issues getting this to work, maybe its not even possible? I have
I am having issues getting this cast to work. The compiler tells me value
I'm having issues getting jQuery to work correctly while testing on Localhost. The function
I am having issues getting the -e and -d file test operators to work
I know it can be done but am having issues getting it to work.
I'm having some issues getting file uploads to work correctly and the following code
I'm having some issues with getting cookies to work when using a ProxyPass to
Having issues getting jQuery to work in this scenario: Visual Studio 2010 .Net 4.0
Having some issues getting this MPMoviePlayerViewController to work. I have two sample URLs pointing
I having issues getting Django to work with settings.py at different location I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.