Mel VIP
Total posts: 126
19 Jan 2014 18:39

I’m making a custom record template. It will be showing a Google map using your address field.

Also at a different position in the same record I would like to show only the street address, city, state and country etc without the map underneath.

How can I achieve this? Thanks for your help

Last Modified: 02 Mar 2014


Sergey
Total posts: 13,748
20 Jan 2014 00:54

You can use something like this

echo $item->field_by_id[10]->value['address']['city'];

And other address elements. Just make

var_dump($item->field_by_id[10]->value)

to see all available array keys.


Mel VIP
Total posts: 126
20 Jan 2014 01:52

I’m sorry but it doesn’t work. Nothing is showing.

Here is how I show the complete map – it works fine:

fields_by_id[23]->result; ?>

So to show just the text I put this:

fields_by_id[23]->value['city']['state']['country']; ?>

but it doesn’t work.


Sergey
Total posts: 13,748
20 Jan 2014 04:09

['city']['state']['country'] will not work. It is 2 level array with first indes address and then other indexes.

echo $item->field_by_id[23]->value['address']['city'];

echo $item->field_by_id[23]->value['address']['state'];

echo $item->field_by_id[23]->value['address']['country'];


Mel VIP
Total posts: 126
20 Jan 2014 05:18

That works just fine now, thanks for your help.


Mel VIP
Total posts: 126
20 Jan 2014 15:55

Hi Sergey

For the instance in the record which shows the Google map, is there a way to remove the location text (city, state, country) from the top?

If I turn off “Who can see address” in the settings, it also turns it off for list view which I do not want.

I looked at the other address elements using: - var_dump($item->field_by_id[10]->value) but I cannot see how to only show the map.

Thanks for your help


Sergey
Total posts: 13,748
21 Jan 2014 00:02

For the instance in the record which shows the Google map, is there a way to remove the location text (city, state, country) from the top?

In articles list of full article view?

What is the top?

Better make screenshot.

For the instance in the record which shows the Google map, is there a way to remove the location text (city, state, country) from the top?

I looked at the other address elements using: - var_dump($item->field_by_id[10]->value) but I cannot see how to only show the map.

You cannot show only map from value. Value contain latitude and longitude only. And result contain HTML of the map. You can only make it by hiding address part in parameters.


Mel VIP
Total posts: 126
21 Jan 2014 00:19

Below is the screenshot. I need to remove the location text circled in red at the top.

I can turn off “Who can see address” in the settings, but it also turns it off for list view. I still need it for list view.


Mel VIP
Total posts: 126
21 Jan 2014 00:20

Above is full article view..


Mel VIP
Total posts: 126
22 Jan 2014 00:45

Hi Sergey, sorry to bother you with this again.

I know that if I turn off display of location text in ‘geo field’ > Address display > Who can view address> no one, then it does not show above the map.

I can then use your answer above to show only the location text in the other place in the custom ‘full’ record template as well as the ‘list’ custom template.

But when I switch the text off in the geo field parameters, the text only view in the custom templates changes.

The country name changes to the abbreviated version. For example “Fremont, California, United States” changes to “Fremont, California, US”.

It’s the same for other countries. The full country name is no longer showing, only the abbreviation.

Is there a way to make it show the full country name?


Sergey
Total posts: 13,748
22 Jan 2014 04:29

FOr every address element you have parameter where to show it. Hide it in full view.


Mel VIP
Total posts: 126
22 Jan 2014 06:38

Yes but if I hide the address fields (using the settings in your screenshot above) it also does not work for the custom display I created in the record view using your code:

fields_by_id[23]->value['address']['city']; ?>,

fields_by_id[23]->value['address']['state']; ?>,

fields_by_id[23]->value['address']['country']; ?>

Instead I have to switch it off at ‘Address display’ > Who can view address. Then your code works but the country full name changes to 2 letters. For example - US instead of United States)

I just need to know how to show the full country name when I use your code to display the address.


Sergey
Total posts: 13,748
22 Jan 2014 06:56

Field value does not depends on any parameter. If it is there it is there. ->value have to have it always if data was saved. No matter what parameters.

Anyway to cet name of the country you have to use special method

echo $this->_getcountryname($country_code)


Mel VIP
Total posts: 126
23 Jan 2014 05:23

Hi Sergey, I tried this:

_getcountryname($item->fields_by_id[23]->value['address']['country']); ?>

but it does not work, it just makes a mess of the template. I'm afraid I do not know enough about php to figure it out myself.


Sergey
Total posts: 13,748
23 Jan 2014 07:08

What does it say? What errors?

May be $item->fields_by_id[23]->value['address']['country'] is empty?


Mel VIP
Total posts: 126
23 Jan 2014 15:36

Hi Sergey

Here are the errors from the error log in the web root. The first 4 appear hundreds of times in the error log so they are there all the time, even when I use the Cobolt default record template. The last one says “Call to undefined method CobaltViewRecord::_getcountryname()”

[23-Jan-2014 21:14:10 Europe/London] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/pdo.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0

[23-Jan-2014 21:14:10 Europe/London] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/pdo_sqlite.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/pdo_sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0

[23-Jan-2014 21:14:10 Europe/London] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/sqlite.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0

[23-Jan-2014 21:14:10 Europe/London] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/pdo_mysql.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0

[23-Jan-2014 21:14:10 Europe/London] PHP Warning: getimagesize(/home/homeswap/new/components/com_cobalt/fields/geo/markers/google/marker-big-red.png) [function.getimagesize]: failed to open stream: No such file or directory in /home/homeswap/new/components/com_cobalt/fields/geo/geo.php on line 898

[23-Jan-2014 21:14:10 Europe/London] PHP Fatal error: Call to undefined method CobaltViewRecord::_getcountryname() in /home/homeswap/new/components/com_cobalt/views/record/tmpl/default_record_mels_default.php on line 165


Sergey
Total posts: 13,748
23 Jan 2014 22:48

I see. I am sorry I was not clear how to use that function.

fields_by_id[23]->_getcountryname($item->fields_by_id[23]->value['address']['country']); ?>

But edit geo.php field file and change protected to public in line 1079


Mel VIP
Total posts: 126
27 Jan 2014 00:35

The code and the edit to the geo.php field worked great. Thanks for your patience with me, I really appreciate it.

To make sure I do not lose the change to the geo.php file at the next upgrade, do I need to make a copy of the “Location and address” field to use?


Sergey
Total posts: 13,748
27 Jan 2014 02:54

To make sure I do not lose the change to the geo.php file at the next upgrade, do I need to make a copy of the “Location and address” field to use?

Yes I have already included it into next update.

Powered by Cobalt