1

How can I add new markers when the user pans the map? For example, my database contains 100,000 markers and loading them all would be unfeasible. When the user moves the map, I would want the script to issue a new call to the database to retrieve the new markers. Here is the code that I have so far:

$url = "http://example.com/products?limit=200&offset=0&lat=40.756623&lng=-73.98487"; $data = file_get_contents($url); $results = json_decode($data,true); $markers = array(); $test = array(); foreach($results as $result) { if(!empty($result['lat']) && !empty($result['lon']) && !empty($result['dealTitle'])) { $key = $result['lat']."_".$result['lon']; if(!in_array($key,$test)) { array_push($test,$key); } $temp = array("text"=>$result['dealTitle'], "latitude"=>$result['lat'], "longitude"=>$result['lon']); array_push($markers,$temp); } }

    // a simple GMap array
      $map_array1 = array(
        'id' => "my-map",         // id attribute for the map
        'width' => "100%",        // map width in pixels or %
        'height' => "400px",      // map height in pixels
        'latitude' => 40.735812,    // map center latitude
        'longitude' => -74.010987,  // map center longitude
        'maptype' => "Map",       // baselayer type
        'markers' => $markers,
      );
      $element1 = array(
        '#type' => 'gmap',
        '#gmap_settings' => $map_array1,
      );
      $html = drupal_render($element1);

  • Anyone have a solution? – John May 26 '14 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.