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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:54:35+00:00 2026-06-01T19:54:35+00:00

Im migrating a working interactive Google Maps V2 to V3 where the web user

  • 0

Im migrating a working interactive Google Maps V2 to V3 where the web user supplies a zip code through a form field which calls a javascript function that runs a query on the database through a PHP script. The PHP script should return the jscript array.

When the jscript function is called (on clicking the form button), nothing is happening. Or the PHP script isn’t returning a jscript array as expected

The error console doesn’t report any error, and firebug shows the function and array variables as expected, however the array variable is empty.

Can someone who has implemented V3 with search function take a look at what I’m doing and give some advice? Thanks in advance:

from html

Enter Zip Code: <input type="text" id="zip" /><input type="button"
onclick="seachLocationsNear()" value="Search Locations" /></p>

from jscript

 function searchLocationsNear(zip) {
 var zipcode = document.getElementById('zip').value;
 var storeloc = 'dbsearch_genArray.php?zip=' + zipcode;
 }

from php

 //query works as expected, returns $result
 //http://www.octoberblue.net/eztrip/dbsearch_genArray.php
 //using while loop to assign query result to jscript array storeloc
 while ($row = @mysql_fetch_assoc($result)){
 print "storeloc.push($row['address'],$row['lat'],$row['lng']);";
 }

Here is the full javascript
//

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

// call setMarkers function on initialization
setMarkers(map, storeloc);
}   

/*
* Define Variables
* storeloc - multidim array, elements title[0],lat[1],lng[2]
* image - string, relative path (from parent html) to icon
* infoWindow - obj, contains info window constructor 
*/
// Works as expected when array is statically defined 
/* var storeloc = [
*   ['4141 Rockside Rd Seven Hills OH', 41.400, -81.663],
*   ['7515 Auburn Road Painesville', 41.66, -81.24],
*   ['2496 E Aurora Road Twinsburg', 41.301218, -81.46940]
*   ];
*/
var image='img/maps_logo.png';   
var infoWindow = new google.maps.InfoWindow({maxWidth:100});
    var marker = new Array();

/*
* dynamically populate the storeloc array when searchLocationsNear() 
* function is called on button click.
*/
function searchLocationsNear(zip) {
var zipcode = document.getElementById('zip').value;
var storeloc = 'dbsearch_genArray.php?zip=' + zipcode;
}

/*
* Define setMarkers function with map and locations parameters
* locations contain storeloc multidim array, called in initialize block.
*/
function setMarkers(map, locations) {
var i;
for (i = 0; i < locations.length; i++) {
  var locate = locations[i];
  var myLatLng = new google.maps.LatLng(locate[1], locate[2]);
  marker[i] = new google.maps.Marker({
     position: myLatLng,
     map: map,
     icon: image,
     title: locate[0]
     });
     google.maps.event.addListener(marker[i],'click',function(){
        markerClick(this);
     });
} //close for loop
} //close setMarkers function

/*
* instanciate InfoWindow for each marker
*/
function markerClick(mark){
var n;
for (n=0; n < marker.length; ++n) {
   if (marker[n] == mark) {
   var infoContent = marker[n].title;
       infoWindow.setContent('<p>Store Location Is:<br>' + infoContent + '</p>');
       infoWindow.open(marker[n], mark);
    }
}
}

/*
* clear markers function, v3 requires the developer to keep
* track of markers and overlays through array.
*/
function clearMarkers() {
infoWindow.close();
var i;
for (i=0; i < markerArray.length; i++) {
    markerArray[i].setMap(null);
}
markerArray.length=0;
}

google.maps.event.addDomListener(window,'load',initialize);
 //]]>

As I noted in the comment, the implementation is working as expected when the storeloc array is statically defined. But not when I try and dynamically create the array through user input.

Thanks in advance,
RWhite35

  • 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-01T19:54:37+00:00Added an answer on June 1, 2026 at 7:54 pm

    After a long and exhaustive week of “trial and error”, I finally have my interactive Google Maps complete with search by zip code functionality. Here is the short answer to the above.

    Users input zip code through a form which runs a PHP query against the client’s MySQL database of store locations. Then using JSON (json_encode()), the PHP array is assigned to a Javascript Array.

     /* assume form input/PHP/MySQL query rans as expect, left out for brevity.
     * $result is a resource id returned by the query process (class object)
     */
     while ($row=@mysql_fetch_assoc($result)){
      $arrLocations[] = (
         array($row['address'],$row['lat'],$row['lng'])
         );
     }
     // Now use JSON to encode the multidim array for JavaScript
     // PHP 5.2 note, must enable in PHP.INI, use cmd line to check: php -i
    
     $arrPassed = json_encode($arrLocations);
    
    ?> //duck out of PHP and in to JS
    <script type="text/javascript"> var storeloc = <?php echo $arrPassed ?>;</script>
    <?php
    //continue PHP and clean up any closures, connections etc.
    

    At this point I have a valid JavaScript multidim array. It can be passed to the setMarkers function above and the rest is go to go. The secret sauce is the JSON encoding. Check the php.net website for json_encode(). This was the cleanest, easiest approach I found to to assigning a PHP multidim array to JavaScript.
    Regards,
    rwhite35

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

Sidebar

Related Questions

Recently i am working on migrating the ASP.NET Web application to MVC. I am
Just working through the Agile Web Development with Rails book and near the closing
I'm working on migrating a project which is very JSP-centric to using Velocity. In
I'm working on a RoR projects. I'm migrating a user table. Because the new
I'm working on migrating code from Visual Basic 6 to Visual Basic.NET, but before
I am working on migrating a 32-bit ISAPI dll to 64-bit. I am using
I am working on migrating Weblogic custom Authentication provider from version 8.1.5 to 9.2.3
I am working on migrating posts from the RightNow infrastructure to another service called
I'm currently working on migrating an application from MS-Access to MS SQL Server. In
I am currently working on ClearCase and now migrating to GIT. But we need

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.