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 4613262
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:31:21+00:00 2026-05-22T01:31:21+00:00

I am just getting underway with google maps api (v3) and it looks good,

  • 0

I am just getting underway with google maps api (v3) and it looks good, but I am having some difficulty retrieving the map object, after it has been declared/initialized elsewhere.

<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(38.90229, -77.021899);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
    myOptions);
  }

  function Search() {
    alert ("Searching...");
    var map = document.getElementById("map_canvas");
    // Want to do is map.setCenter(...) but I don't know how to retrieve the map object
  }

</script>

See the Search function I’m working on? I want to re-center the map, ultimately. But, generally, I want to retrieve the map object that was created upon initialization.

Thank you.

  • 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-05-22T01:31:22+00:00Added an answer on May 22, 2026 at 1:31 am

    You should return the map in intialize() (and possibly change the name of the function). The way you have it now, it’s just a local variable inside the initialize() function. So, the last line of the initialize function should be more like

    return new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    

    Then when you call initialize, assign the return value to a variable, say called map. Once you have the map object returned into a variable, you can recenter with:

    map.setCenter(new google.maps.LatLng(lat, lon)); 
    

    The way you have it now, you’ll probably want to pass map as a parameter to Search().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just getting my teeth sunk into google maps API. I am attempting to plot
I'm just getting into creating some WCF services, but I have a requirement to
Just getting my feet wet with some Fluent NHibernate AutoMap conventions, and ran into
Just getting the hang of Spring Webflow. I have some simple forms working and
Just getting my head around Linq and having lots of fun! Can any one
Just getting started with jQuery, and I've had some success so far. I've created
Just getting started with C++, done a bit of C but one thing I
Just getting off my JavaScript training wheels. Why does Google choose to unescape the
Just getting into Unit Testing with C++. It looks like I will need to
Just getting started with Obj-C and iOS programming. I have some code that loads

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.