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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:05:58+00:00 2026-05-21T23:05:58+00:00

I am trying to create a real-time searchbox so my users can search for

  • 0

I am trying to create a real-time searchbox so my users can search for locations on my website.
I have been using JqueryUI Autocomplete function and GoogleMap API for the suggestions list.

Here’s the code:

...
<script type="text/javascript" src="js/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.12.custom.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
</head>

<body>
<div id="content">
    <h1>Google Maps Autocomplete Search Sample</h1>
    <div align="left">
        <form method="post" action="#">
            <input type="text" value="" id="searchbox" name="searchbox" style=" width:800px;height:30px; font-size:15px;">
            <input type="submit" />
            <div class="ui-widget" style="margin-top:2em; font-family:Arial">
                Result:
                <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
            </div>
        </form>
    </div>
    <div align="left" id="map" style="width:800px; height: 600px; margin-top: 10px; ">  
    </div>
</div>
<?php
include_once('inc/foot.php');
?>
<script type="text/javascript">
 $(document).ready(function(){

  var mapOptions = {
       zoom: 10,
       mapTypeId: google.maps.MapTypeId.ROADMAP,
       center: new google.maps.LatLng(41.06000,28.98700)
     };



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

  var geocoder = new google.maps.Geocoder();  

     $(function() {

         function log( message ) {
            $( "<div/>" ).text( message ).prependTo( "#log" );
            $( "#log" ).attr( "scrollTop", 0 );
        }

         $("#searchbox").autocomplete({

           source: function(request, response) {

          if (geocoder == null){
           geocoder = new google.maps.Geocoder();
          }
             geocoder.geocode( {'address': request.term }, function(results, status) {
               if (status == google.maps.GeocoderStatus.OK) {

                  var searchLoc = results[0].geometry.location;
               var lat = results[0].geometry.location.lat();
                  var lng = results[0].geometry.location.lng();
                  var latlng = new google.maps.LatLng(lat, lng);
                  var bounds = results[0].geometry.bounds;

                  geocoder.geocode({'latLng': latlng}, function(results1, status1) {
                      if (status1 == google.maps.GeocoderStatus.OK) {
                        if (results1[1]) {
                         response($.map(results1, function(loc) {
                        return {
                            label  : loc.formatted_address,
                            value  : loc.formatted_address+loc.geometry.location,
                            bounds   : loc.geometry.bounds
                          }
                        }));
                        }
                      }
                    });
            }
              });
           },
            select: function(event,ui){
                var pos = ui.item.position;
                var lct = ui.item.locType;
                var bounds = ui.item.bounds;
                log( ui.item ?
                    ui.item.value :
                    "undefined_by_google" + this.value );

      if (bounds){
       map.fitBounds(bounds);
      }
           }
         });
     });   
 });
</script>

I’d like to find a way to load the div (#log) only with the coordinates while the search input (#searchbox) keeps on showing the text value.

I hope it’s clear enough, otherwise just ask me…
Thanks for your help

EDIT

Problem solved, It was quiet easy, just needed:

$(“#log”).html(“latitude:” + lat + “longitude:” + lng);

Thanks for having a look at it Edgar

  • 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-21T23:05:59+00:00Added an answer on May 21, 2026 at 11:05 pm

    You just have to add one line of code and then make one change:

    This will save your last location in a string:

                  lastLoc='('+lat+','+lng+')';
    

    and this will print it to the log:

    log( ui.item ? lastLoc : "undefined_by_google" + this.value );
    

    See the fiddle to see where these lines go:
    working example

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

Sidebar

Related Questions

I'm trying to create an application which monitors users like data in real time.
I am trying to use matplotlib to create a graph to reflect real time
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying to create a search for my website over a mySQL database.
I am trying to create a socket server in C for a Collaborative real-time
I am trying to learn how to create a more real time callback from
I'm trying to create a real-time charting utility in android, and for the most
Ok so I am trying create a login script, here I am using PHP5
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
I'm trying to display a UIImage in real-time coming from the camera, and it

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.