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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:31:33+00:00 2026-05-28T05:31:33+00:00

This is what I want to do: I ask the user to type a

  • 0

This is what I want to do: I ask the user to type a latitude+longitude into an input box and I want to show a marker on the map for that location, without having to initialize the map every time.

I have initialized a map as follows:

<script type="text/javascript">
    jQuery(document).ready(function() {
    var myOptions = {
          center: new google.maps.LatLng(34.053228, -118.259583),
          zoom: 12,
          zoomControl: true,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    });
</script>
<div style='height: 400px;'>
    <div id="map_canvas" style="width:100%; float: left; height:100%"></div>
</div>

No jazz till now, this is the normal way of defining a map. Now, I have an input box, where I ask the user to type an address:

<input type="text" size=30 name="lat" id="lat">
<input type="text" size=30 name="lon" id="lon">
<button type="button" id="address_submit">Search</button>

I want to show the marker for that address. I defined a function, shown below, but am not getting how to show get the map object:

    $("#address_submit").live("click", function() {
    lat = $("#lat").val();
    lon = $("#lon").val();
    var marker = new google.maps.Marker({
          position: new google.maps.LatLng(lat, lon),
          map: map, //HOW DO I GET THIS MAP OBJECT??
          title:"Hello World!"
      });
}
  • 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-28T05:31:34+00:00Added an answer on May 28, 2026 at 5:31 am

    I’ve tried your code in a jsfiddle => http://jsfiddle.net/HaDbR/ and all seems to work as expected (I’ve reduced a bit the zoom factor just to see inserted markers): I’ve inserted some coordinates in the form (near to the map center coords) and the markers appeared correctly.

    The only real differences is the visibility of map variable so that the click handler applied to the button can see it, and the .on() method instead of .live()

    I’ve inserted the googlemap API script, calling a callback function createMap() and in that function I’ve initialized the map and I’ve associated the handler, so by closure it can have access to your map

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

Sidebar

Related Questions

I am not even sure how to ask this question. I want something that
In a follow-up to this answer I want to ask if any of you
I want to ask why we use this keyword before the parameter in an
I ask this academically, I want to ask aloud a very important question and
Probably many coders want to ask this question. it is What's the adventages of
Before I ask this, do note: I want this for debugging purposes. I know
I ask this because I want to display a page in iframe and on
How do I get and print a char from a user? This want do
I ask this partly because I want to know the best practice way of
First: I'm shocked that I have to ask this question. Nowhere in the docs

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.