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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:25:35+00:00 2026-05-19T02:25:35+00:00

EDITED : The problem is with the function ‘find_callback’, I want to insert each

  • 0

EDITED: The problem is with the function ‘find_callback’, I want to insert each of the responses to a global array named responseArray. the response is an array of objects.

I’m trying to add markers to the Waze implementation of OpenLayers from an array of searches. I want to run multiple searches, accumulating the results. I use 3 functions, onInit(), find_callback() and addPoint(). Calling the ‘find_callback’ function overrides the previous markers. If I run a single search:

g_wzae_map.find('THE LOCATION', 'find_callback');

The response:

/* array of search results (up to 10) sorted by relevancy */
[ {
    //bounds that contain the this map feature (set map to this extent for closest zoom)
    "bounds":{"bottom":32.0880470275879,
    "left":34.7883338928223,
    "right":34.7912673950195,
    "top":32.0854721069336},
    //location of the feature
    "location":{"lat":32.08560397003471,"lon":34.78999763465419},
    //name of feature
    "name":"Street, City"
  },
  //up to 9 more results
  // ...
]

The code as it is

function addPoint(response){
    var first_result = response;
    var lon = first_result.location.lon;
    var lat = first_result.location.lat;
    map.setCenter(new OpenLayers.LonLat(lon,lat));

    var markersPoint = new OpenLayers.Layer.Markers( "Markers" );
    markersPoint.addMarker(
        new OpenLayers.Marker(
            new OpenLayers.LonLat(
                lon,
                lat
                ),
            icon.clone()
            )
        );
    g_waze_map.map.addLayer(markersPoint);

    map.addPopup(
        new OpenLayers.Popup.FramedCloud(
            "point_"+first_result.location.lat,
            new OpenLayers.LonLat(lon,lat),
            null,
            "<div style='font-family:Arial,sans-serif;font-size:0.8em;'>"
            +first_result.name+"<div>",
            anchor=null,
            true,
            null
            )
        );

}


//called when map loads
function onInit(){
    map = g_waze_map.map;

    size    = new OpenLayers.Size(15, 20);
    offset  = new OpenLayers.Pixel(-(size.w/2), -size.h);
    icon    = new OpenLayers.Icon('http://www.waze.co.il/images/home.png',size,offset);         

    // array for the points
    responseArray = new Array();
    // find callback
   find_callback = function(response){
        for (var i=0, length = response.length; i<length; i++){
            responseArray.push(response[i]);
        }
        // alert(responseArray[0]); // working, getting an object
    }
    // alert(responseArray[0]); // not working, getting 'undefined'

    //search API example, calls 'find_callback' when search returns
    g_waze_map.find('Turin','find_callback');
    g_waze_map.find('Rome','find_callback', true);
    // adding the points
    for (var i=0, length = responseArray.length; i<length; i++){
        addPoint(responseArray[i]);
    }
};

Thanks!

  • 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-19T02:25:36+00:00Added an answer on May 19, 2026 at 2:25 am

    g_waze_map.find() is asynchronous, which is why it uses a callback to process results. When find returns, the search results probably aren’t available. Instead of calling addPoint from onInit, call it directly in find_callback.

    find loads search results in another page, which might be storing the results as a global variable that gets clobbered when later calls reload the page (see why globals are bad?). If that’s the case, you can move all but the first call to find to the find callback.

    //called when map loads
    function onInit(){
        var map = g_waze_map.map;
    
        var size    = new OpenLayers.Size(15, 20);
        var offset  = new OpenLayers.Pixel(-(size.w/2), -size.h);
        var icon    = new OpenLayers.Icon('http://www.waze.co.il/images/home.png',size,offset);         
    
        function addPoint(response){
            var first_result = response;
            var lon = response.location.lon;
            var lat = response.location.lat;
            //g_waze_map.map.setCenter(new OpenLayers.LonLat(lon,lat));
    
            var markersPoint = new OpenLayers.Layer.Markers( "Markers" );
            markersPoint.addMarker(
                new OpenLayers.Marker(
                    new OpenLayers.LonLat(lon, lat),
                    icon.clone()
            )   );
            g_waze_map.map.addLayer(markersPoint);
    
            g_waze_map.map.addPopup(
                new OpenLayers.Popup.FramedCloud(
                    "point_"+lat, new OpenLayers.LonLat(lon,lat), null,
                    "<div style='font-family:Arial,sans-serif;font-size:0.8em;'>"+response.name+"<div>",
                    null, true, null
             )  );
        }
    
        // array for the points; this could be dropped
        var responseArray = [];
        function addPoints(response) {
            // if you want to save the responses for other purposes
            Array.push.apply(responseArray, response);
            for (var i=0, length = response.length; i<length; i++){
                addPoint(response[i]);
            }
        }
    
        var terms = ['Rome'];
        window.find_callback = function(response){
            addPoints(response);
            if (terms.length) {
                g_waze_map.find(terms.pop(),'find_callback', true);
            }
        }
    
        g_waze_map.find('Turin','find_callback');
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: edited files on windows, using git-bash, to fix IE7 problems committed, pushed to
Edit: I've edited the sample to better resemble the problem I have, now the
I want to write a Python program that makes PNG files. My big problem
I edited the question after David Hanak's answer (thanks btw!). He helped with the
This is a sample (edited slightly, but you get the idea) of my XML
I have HTML code edited by FCKEditor stored in a database and would like
How do I load the edited .emacs file without restarting Emacs?
I have a JavaScript resource that has the possibility of being edited at any
Here is an example of polymorphism from http://www.cplusplus.com/doc/tutorial/polymorphism.html (edited for readability): // abstract base
My VB.Net Winforms app is a tool to allow hierarchical data to be edited

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.