Skip to main content
replaced http://drupal.stackexchange.com/ with https://drupal.stackexchange.com/
Source Link

Am trying to create a health service locator using Google maps API on my Drupal 7 site. (FYI, I cant use location module or open layers, because, Create a hospital locator in drupal 7Create a hospital locator in drupal 7 )

OK, so now I have a form, which takes the users location, type of service (eg, hospital, pharmacy etc) and the proximity around which they wish to find the result, using Google Maps API and Google Places API I fetch the results (details about those near by places such as hospital) in JSON format from Google. The fetched data includes each place's name, address, rating, phone number, latitude, longitude etc. now I store those values in form_state['storage'] and then sends it to the JS file using the drupal_add_js() method.

The below code is sending the values,

<?php
for($i=0;$i<$length;$i++)
 {
  drupal_add_js(array('a'.$i =>array(
             'lat'=> $form_state['storage']['results'][$i]['geometry']['location']['lat'],
             'long'=> $form_state['storage']['results'][$i]['geometry']['location']['long'],  
         'name'=>  $form_state['storage']['results'][$i]['name'],
         'rating'=>$form_state['storage']['results'][$i]['rating'],
         'vicinity'=>$form_state['storage']['results'][$i]['vicinity'],
         'formatted_address'=>$form_state['storage']['results'][$i]['formatted_address'],
         'international_phone_number'=>$form_state['storage']['results'][$i]['international_phone_number'],
         'website'=>$form_state['storage']['results'][$i]['website'],
)),'setting');

}
?>.

the details of first place is in a0, second place detail is in a1 etc.

FYI, each place details are in Drupal.settings.a0, Drupal.settings.a1 etc. I mean, I can access those variables in js file using,

Drupal.settings.a0.name and Drupal.settings.a0.website similarly for second place, Drupal.settings.a1.name etc.

Now my problem is I need to iterate through these different places.

I can iterate through different variables of one particular place usin the below for loop,

for(var x in Drupal.settings.a0)
{
 alert(Drupal.settings.a0.x);
}

But, I cant iterate through different places, like a0, a1 etc. I mean I cant attach a variable to drupal.settings..!

I tried tried putting all places in an array, i.e, a0,a1,a2 are in an array named arr[] (I have the total no. of places in Drupal.settings.my_vars.length) then, I iterate through this array and tried attaching arr[i] to Drupal.settings as Drupal.settings.arr[i].x but it doesn't work.

How can I do it...?? Is there any better way of achieving it...??

Thanks in advance.

Am trying to create a health service locator using Google maps API on my Drupal 7 site. (FYI, I cant use location module or open layers, because, Create a hospital locator in drupal 7 )

OK, so now I have a form, which takes the users location, type of service (eg, hospital, pharmacy etc) and the proximity around which they wish to find the result, using Google Maps API and Google Places API I fetch the results (details about those near by places such as hospital) in JSON format from Google. The fetched data includes each place's name, address, rating, phone number, latitude, longitude etc. now I store those values in form_state['storage'] and then sends it to the JS file using the drupal_add_js() method.

The below code is sending the values,

<?php
for($i=0;$i<$length;$i++)
 {
  drupal_add_js(array('a'.$i =>array(
             'lat'=> $form_state['storage']['results'][$i]['geometry']['location']['lat'],
             'long'=> $form_state['storage']['results'][$i]['geometry']['location']['long'],  
         'name'=>  $form_state['storage']['results'][$i]['name'],
         'rating'=>$form_state['storage']['results'][$i]['rating'],
         'vicinity'=>$form_state['storage']['results'][$i]['vicinity'],
         'formatted_address'=>$form_state['storage']['results'][$i]['formatted_address'],
         'international_phone_number'=>$form_state['storage']['results'][$i]['international_phone_number'],
         'website'=>$form_state['storage']['results'][$i]['website'],
)),'setting');

}
?>.

the details of first place is in a0, second place detail is in a1 etc.

FYI, each place details are in Drupal.settings.a0, Drupal.settings.a1 etc. I mean, I can access those variables in js file using,

Drupal.settings.a0.name and Drupal.settings.a0.website similarly for second place, Drupal.settings.a1.name etc.

Now my problem is I need to iterate through these different places.

I can iterate through different variables of one particular place usin the below for loop,

for(var x in Drupal.settings.a0)
{
 alert(Drupal.settings.a0.x);
}

But, I cant iterate through different places, like a0, a1 etc. I mean I cant attach a variable to drupal.settings..!

I tried tried putting all places in an array, i.e, a0,a1,a2 are in an array named arr[] (I have the total no. of places in Drupal.settings.my_vars.length) then, I iterate through this array and tried attaching arr[i] to Drupal.settings as Drupal.settings.arr[i].x but it doesn't work.

How can I do it...?? Is there any better way of achieving it...??

Thanks in advance.

Am trying to create a health service locator using Google maps API on my Drupal 7 site. (FYI, I cant use location module or open layers, because, Create a hospital locator in drupal 7 )

OK, so now I have a form, which takes the users location, type of service (eg, hospital, pharmacy etc) and the proximity around which they wish to find the result, using Google Maps API and Google Places API I fetch the results (details about those near by places such as hospital) in JSON format from Google. The fetched data includes each place's name, address, rating, phone number, latitude, longitude etc. now I store those values in form_state['storage'] and then sends it to the JS file using the drupal_add_js() method.

The below code is sending the values,

<?php
for($i=0;$i<$length;$i++)
 {
  drupal_add_js(array('a'.$i =>array(
             'lat'=> $form_state['storage']['results'][$i]['geometry']['location']['lat'],
             'long'=> $form_state['storage']['results'][$i]['geometry']['location']['long'],  
         'name'=>  $form_state['storage']['results'][$i]['name'],
         'rating'=>$form_state['storage']['results'][$i]['rating'],
         'vicinity'=>$form_state['storage']['results'][$i]['vicinity'],
         'formatted_address'=>$form_state['storage']['results'][$i]['formatted_address'],
         'international_phone_number'=>$form_state['storage']['results'][$i]['international_phone_number'],
         'website'=>$form_state['storage']['results'][$i]['website'],
)),'setting');

}
?>.

the details of first place is in a0, second place detail is in a1 etc.

FYI, each place details are in Drupal.settings.a0, Drupal.settings.a1 etc. I mean, I can access those variables in js file using,

Drupal.settings.a0.name and Drupal.settings.a0.website similarly for second place, Drupal.settings.a1.name etc.

Now my problem is I need to iterate through these different places.

I can iterate through different variables of one particular place usin the below for loop,

for(var x in Drupal.settings.a0)
{
 alert(Drupal.settings.a0.x);
}

But, I cant iterate through different places, like a0, a1 etc. I mean I cant attach a variable to drupal.settings..!

I tried tried putting all places in an array, i.e, a0,a1,a2 are in an array named arr[] (I have the total no. of places in Drupal.settings.my_vars.length) then, I iterate through this array and tried attaching arr[i] to Drupal.settings as Drupal.settings.arr[i].x but it doesn't work.

How can I do it...?? Is there any better way of achieving it...??

Thanks in advance.

added 15 characters in body; edited title
Source Link
Chapabu
  • 13.9k
  • 2
  • 40
  • 58

How to iterate through Drupal.settings (variables sent using drupal_add_js from a .php file) in a js file when there are lots of variables ...?

Am trying to create a health service locator using googleGoogle maps apiAPI on my drupalDrupal 7 site. (FYI, I cant use location module or open layers, because, Create a hospital locator in drupal 7 )

K nowOK, so now I have a form, which takes user'sthe users location, kindtype of service (eg, hospital, pharmacy etc) and the proximity around which they wish to find the result, using google maps apiGoogle Maps API and google places apiGoogle Places API I fetch the results (details about those near by places such as hospital) in jsonJSON format from googleGoogle. The fetched data, include, includes each place's name,address address,rating rating,phone phone number,lattitude latitude,longitude longitude etc. now I store those values in form_state['storage'] and then sendsends it to the jsJS file using the drupal_add_js() method.

The below code is sending the values,

<?php
for($i=0;$i<$length;$i++)
 {
  drupal_add_js(array('a'.$i =>array(
             'lat'=> $form_state['storage']['results'][$i]['geometry']['location']['lat'],
             'long'=> $form_state['storage']['results'][$i]['geometry']['location']['long'],  
         'name'=>  $form_state['storage']['results'][$i]['name'],
         'rating'=>$form_state['storage']['results'][$i]['rating'],
         'vicinity'=>$form_state['storage']['results'][$i]['vicinity'],
         'formatted_address'=>$form_state['storage']['results'][$i]['formatted_address'],
         'international_phone_number'=>$form_state['storage']['results'][$i]['international_phone_number'],
         'website'=>$form_state['storage']['results'][$i]['website'],
)),'setting');

}
?>.

the details of first place is in a0, second place detail is in a1 etc.

FYI, each place details are in Drupal.settings.a0, Drupal.settings.a1 etc. I mean, I can access those variables in js file using,

Drupal.settings.a0.name and Drupal.settings.a0.website similarly for second place, Drupal.settings.a1.name etc.

Now my problem is I need to iterate through these different places.

I can iterate through different variables of one particular place usin the below for loop,

for(var x in Drupal.settings.a0)
{
 alert(Drupal.settings.a0.x);
}

But, I cant iterate through different places, like a0, a1 etc. I mean I cant attach a variable to drupal.settings..!

I tried tried putting all places in an array, i.e, a0,a1,a2 are in an array named arr[] (I have the total no. of places in Drupal.settings.my_vars.length) then, I iterate through this array and tried attaching arr[i] to Drupal.settings as Drupal.settings.arr[i].x but it doesn't work.

How can I do it...?? Is there any better way of achieving it...??

Thanks in advance.

How to iterate through Drupal.settings (variables sent using drupal_add_js from a .php file) in a js file when there are lots of variables ...?

Am trying to create a health service locator using google maps api on my drupal 7 site. (FYI, I cant use location module or open layers, because, Create a hospital locator in drupal 7 )

K now, I have a form, which takes user's location, kind of service (eg, hospital, pharmacy etc) and the proximity around which they wish to find the result, using google maps api and google places api I fetch the results (details about those near by places such as hospital) in json format from google. The fetched data, include, each place's name,address,rating,phone number,lattitude,longitude etc. now I store those values in form_state['storage'] and then send it to the js file using drupal_add_js() method.

The below code is sending the values,

<?php
for($i=0;$i<$length;$i++)
 {
  drupal_add_js(array('a'.$i =>array(
             'lat'=> $form_state['storage']['results'][$i]['geometry']['location']['lat'],
             'long'=> $form_state['storage']['results'][$i]['geometry']['location']['long'],  
         'name'=>  $form_state['storage']['results'][$i]['name'],
         'rating'=>$form_state['storage']['results'][$i]['rating'],
         'vicinity'=>$form_state['storage']['results'][$i]['vicinity'],
         'formatted_address'=>$form_state['storage']['results'][$i]['formatted_address'],
         'international_phone_number'=>$form_state['storage']['results'][$i]['international_phone_number'],
         'website'=>$form_state['storage']['results'][$i]['website'],
)),'setting');

}
?>.

the details of first place is in a0, second place detail is in a1 etc.

FYI, each place details are in Drupal.settings.a0, Drupal.settings.a1 etc. I mean, I can access those variables in js file using,

Drupal.settings.a0.name and Drupal.settings.a0.website similarly for second place, Drupal.settings.a1.name etc.

Now my problem is I need to iterate through these different places.

I can iterate through different variables of one particular place usin the below for loop,

for(var x in Drupal.settings.a0)
{
 alert(Drupal.settings.a0.x);
}

But, I cant iterate through different places, like a0, a1 etc. I mean I cant attach a variable to drupal.settings..!

I tried tried putting all places in an array, i.e, a0,a1,a2 are in an array named arr[] (I have the total no. of places in Drupal.settings.my_vars.length) then, I iterate through this array and tried attaching arr[i] to Drupal.settings as Drupal.settings.arr[i].x but it doesn't work.

How can I do it...?? Is there any better way of achieving it...??

Thanks in advance.

How to iterate through Drupal.settings in a js file when there are lots of variables?

Am trying to create a health service locator using Google maps API on my Drupal 7 site. (FYI, I cant use location module or open layers, because, Create a hospital locator in drupal 7 )

OK, so now I have a form, which takes the users location, type of service (eg, hospital, pharmacy etc) and the proximity around which they wish to find the result, using Google Maps API and Google Places API I fetch the results (details about those near by places such as hospital) in JSON format from Google. The fetched data includes each place's name, address, rating, phone number, latitude, longitude etc. now I store those values in form_state['storage'] and then sends it to the JS file using the drupal_add_js() method.

The below code is sending the values,

<?php
for($i=0;$i<$length;$i++)
 {
  drupal_add_js(array('a'.$i =>array(
             'lat'=> $form_state['storage']['results'][$i]['geometry']['location']['lat'],
             'long'=> $form_state['storage']['results'][$i]['geometry']['location']['long'],  
         'name'=>  $form_state['storage']['results'][$i]['name'],
         'rating'=>$form_state['storage']['results'][$i]['rating'],
         'vicinity'=>$form_state['storage']['results'][$i]['vicinity'],
         'formatted_address'=>$form_state['storage']['results'][$i]['formatted_address'],
         'international_phone_number'=>$form_state['storage']['results'][$i]['international_phone_number'],
         'website'=>$form_state['storage']['results'][$i]['website'],
)),'setting');

}
?>.

the details of first place is in a0, second place detail is in a1 etc.

FYI, each place details are in Drupal.settings.a0, Drupal.settings.a1 etc. I mean, I can access those variables in js file using,

Drupal.settings.a0.name and Drupal.settings.a0.website similarly for second place, Drupal.settings.a1.name etc.

Now my problem is I need to iterate through these different places.

I can iterate through different variables of one particular place usin the below for loop,

for(var x in Drupal.settings.a0)
{
 alert(Drupal.settings.a0.x);
}

But, I cant iterate through different places, like a0, a1 etc. I mean I cant attach a variable to drupal.settings..!

I tried tried putting all places in an array, i.e, a0,a1,a2 are in an array named arr[] (I have the total no. of places in Drupal.settings.my_vars.length) then, I iterate through this array and tried attaching arr[i] to Drupal.settings as Drupal.settings.arr[i].x but it doesn't work.

How can I do it...?? Is there any better way of achieving it...??

Thanks in advance.

Source Link

How to iterate through Drupal.settings (variables sent using drupal_add_js from a .php file) in a js file when there are lots of variables ...?

Am trying to create a health service locator using google maps api on my drupal 7 site. (FYI, I cant use location module or open layers, because, Create a hospital locator in drupal 7 )

K now, I have a form, which takes user's location, kind of service (eg, hospital, pharmacy etc) and the proximity around which they wish to find the result, using google maps api and google places api I fetch the results (details about those near by places such as hospital) in json format from google. The fetched data, include, each place's name,address,rating,phone number,lattitude,longitude etc. now I store those values in form_state['storage'] and then send it to the js file using drupal_add_js() method.

The below code is sending the values,

<?php
for($i=0;$i<$length;$i++)
 {
  drupal_add_js(array('a'.$i =>array(
             'lat'=> $form_state['storage']['results'][$i]['geometry']['location']['lat'],
             'long'=> $form_state['storage']['results'][$i]['geometry']['location']['long'],  
         'name'=>  $form_state['storage']['results'][$i]['name'],
         'rating'=>$form_state['storage']['results'][$i]['rating'],
         'vicinity'=>$form_state['storage']['results'][$i]['vicinity'],
         'formatted_address'=>$form_state['storage']['results'][$i]['formatted_address'],
         'international_phone_number'=>$form_state['storage']['results'][$i]['international_phone_number'],
         'website'=>$form_state['storage']['results'][$i]['website'],
)),'setting');

}
?>.

the details of first place is in a0, second place detail is in a1 etc.

FYI, each place details are in Drupal.settings.a0, Drupal.settings.a1 etc. I mean, I can access those variables in js file using,

Drupal.settings.a0.name and Drupal.settings.a0.website similarly for second place, Drupal.settings.a1.name etc.

Now my problem is I need to iterate through these different places.

I can iterate through different variables of one particular place usin the below for loop,

for(var x in Drupal.settings.a0)
{
 alert(Drupal.settings.a0.x);
}

But, I cant iterate through different places, like a0, a1 etc. I mean I cant attach a variable to drupal.settings..!

I tried tried putting all places in an array, i.e, a0,a1,a2 are in an array named arr[] (I have the total no. of places in Drupal.settings.my_vars.length) then, I iterate through this array and tried attaching arr[i] to Drupal.settings as Drupal.settings.arr[i].x but it doesn't work.

How can I do it...?? Is there any better way of achieving it...??

Thanks in advance.