Jump to content


Photo

Google map module


  • Please log in to reply
17 replies to this topic

#1 qwertyeee

qwertyeee

    Jr. Member

  • Members
  • PipPip
  • 23 posts
  • 0

Posted 03 March 2011 - 05:53 AM

Google map module.

for use

add in template

<link rel="stylesheet" type="text/css" href="<?php echo $config->urls->FieldtypeGMap?>styles/FieldtypeGMap.css" />

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="<?php echo $config->urls->FieldtypeGMap?>scripts/FieldtypeGMap.js"></script>

$out = '<textarea id="Fieldtype_GMap_location" class="GMap_hidden_textarea">'.htmlspecialchars($page->GMap_location).'</textarea>';
$out .= '<div class="GMap_canvas" id="GMap_location"></div>'; 
$out .= '<script type="text/javascript">';
$out .= 'var GMap_location = new Map("GMap_location");';
$out .= '</script>';
echo($out);

replace GMap_location with your field name

$out = '<textarea id="Fieldtype_your_filed_name" class="GMap_hidden_textarea">'.htmlspecialchars($page->your_filed_name).'</textarea>';
$out .= '<div class="GMap_canvas" id="your_filed_name"></div>'; 
$out .= '<script type="text/javascript">';
$out .= 'var your_filed_name = new Map("your_filed_name");';
$out .= '</script>';
echo($out);

Attached Files

  • Attached File  GMap.zip   4.92KB   289 downloads


#2 ryan

ryan

    Reiska

  • Administrators
  • 7,783 posts
  • 6528

  • LocationAtlanta, GA

Posted 03 March 2011 - 06:57 PM

Hope you don't mind, but I added some stuff to your GMap module for fun. I modified it so that it has a field configuration option for "add markup automatically". So if you check that option on the field, then you don't have to add any code in your template other than this:

<?=$page->map?>

In the above, snippet, you would replace 'map' with your map field name.

The updated file is attached. I think this is what you were trying to do before when we were writing in the other thread, so I figured it would be worthwhile for me to add it, in case it helps to demonstrate how.

Another thing that I think would be cool is if there was a configuration option for it to pull an address from some other text field on the page. Then it would geocode and save it, so that it doesn't have to geocode again. Though I'm not yet sure how to do that, so just thinking... :)

Thanks again for your work in putting this module together. This is something I will definitely use.

Edit: Accidentally left a debug "echo" statement in the previous module, so have replaced it with a new version. 

Attached Files



#3 qwertyeee

qwertyeee

    Jr. Member

  • Members
  • PipPip
  • 23 posts
  • 0

Posted 04 March 2011 - 01:59 AM

cool

#4 ryan

ryan

    Reiska

  • Administrators
  • 7,783 posts
  • 6528

  • LocationAtlanta, GA

Posted 04 March 2011 - 03:16 PM

I was just testing out this screencast service that I saw Apeisa's been using, and made a little screencast demonstrating installation and use of your GMap module. http://screencast.com/t/IaCFikQwn

#5 marcin

marcin

    Jr. Member

  • Members
  • PipPip
  • 33 posts
  • 1

Posted 25 March 2011 - 11:06 AM

I removed folder with GMap module by mistake and unpacked there new files, but now I get message:
"Exception: Fieldtype 'FieldtypeGMap' does not exist (in /var/www/pw/wire/core/Field.php line 156)

How can I:
a) uninstall old instance of GMap(I'm afraid of incoherence in database) or
b) set up installation manually?


#6 ryan

ryan

    Reiska

  • Administrators
  • 7,783 posts
  • 6528

  • LocationAtlanta, GA

Posted 25 March 2011 - 07:03 PM

To uninstall something you want to do it through admin>modules. If the dir/files were removed without uninstalling, it's best to put them back where they were. It sounds like you may have already tried this? If so double check that the dirname and filenames are the same as before.  If that still doesn't work, you can always remove the entry from the modules table manually, if you are sure it's not actively being used on any fields. Better yet, try deleting the modules cache file in site/assets/. I dont recall what the filename is (I'm not at computer) but I think the name is recognizable as being for modules. Please let me know how this works out.

#7 marcin

marcin

    Jr. Member

  • Members
  • PipPip
  • 33 posts
  • 1

Posted 25 March 2011 - 09:03 PM

Solution was really simple - file perms. I thought that module installation is rather complicated(creating/moving some files) so I forgot about such a basic thing.

Thank you for your comprehensive reply(as always).

#8 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 263 posts
  • 46

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 30 August 2011 - 04:20 AM

I would like to display the map (using
<?=$page->map?>
) only when I've set a value in the database, since I don't want to display a map with default location.

Is this possible?

How would the if-statement look like? I tried several things, but could not get it working...

Thanks in advance!

/Jasper

#9 Pete

Pete

    Forum Admin

  • Administrators
  • 2,375 posts
  • 1424

  • LocationChester, England

Posted 30 August 2011 - 07:55 AM

This mightwork:

<? echo $page->map ? $page->map : ''; ?>


#10 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 263 posts
  • 46

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 30 August 2011 - 08:25 AM

This mightwork:

<? echo $page->map ? $page->map : ''; ?>


Thank you for your reply. Unfortunately it doesn't work.
And if it worked it wouldn't have solved my problem completely (but you couldn't know that).

What I am looking for is something like:
if "google_maps is exists" {
display map with surrounding div, makup etc.
}

/Jasper

#11 ryan

ryan

    Reiska

  • Administrators
  • 7,783 posts
  • 6528

  • LocationAtlanta, GA

Posted 30 August 2011 - 08:27 AM

I didn't write the module (other than adding a few edits), so can't say for certain, but I'm thinking this might work:

<?php
$page->setOutputFormatting(false);
if($page->map) {
    // display the map
    $page->setOutputFormatting(true); 
    echo $page->map;
} else {
    // no map to display.
    $page->setOutputFormatting(true); 
}

If that doesn't work, you may want to just modify the module itself. I would  try editing the formatValue() function and adding this at the top:

if(!$value) return '';

Lastly, another option is that you could edit map field's config settings and turn off the auto-generated map markup. Then generate your own (like in the earlier examples in this thread).



#12 formmailer

formmailer

    Sr. Member

  • Members
  • PipPipPipPip
  • 263 posts
  • 46

  • LocationHudiksvall, Sweden (but originally from The Netherlands)

Posted 30 August 2011 - 08:40 AM

I didn't write the module (other than adding a few edits), so can't say for certain, but I'm thinking this might work:

<?php
$page->setOutputFormatting(false);
if($page->map) {
    // display the map
    $page->setOutputFormatting(true); 
    echo $page->map;
} else {
    // no map to display.
    $page->setOutputFormatting(true); 
}


This works!  ;D

Thanks!

/Jasper

#13 neildaemond

neildaemond

    Sr. Member

  • Members
  • PipPipPipPip
  • 123 posts
  • 32

  • LocationHong Kong

Posted 07 November 2011 - 10:28 PM

Thanks for the module guys, and the clear installation instructions. I am impressed every time I see Ryan solve someone problems with just one quick reply...

Anyhow, I installed this module and tried it out. However, in the page edit screen, all I saw was a grey box where the map was supposed to load.

I added the field to the page template. I haven't yet added the $page->map into the template file...

Any ideas where to start debugging this? I am running this on my home Ubuntu server which I use for development.. so my configurations could be off~ I tried firefox and explorer and got the same result~

EDIT: wait... explorer gave the error message "stack overflow on line: 28"

#14 Michael Murphy

Michael Murphy

    Distinguished Member

  • Members
  • PipPipPipPip
  • 101 posts
  • 66

  • LocationBasel, Switzerland

Posted 08 November 2011 - 05:41 AM

I have been meaning to report this bug for a while.

If you see the gray box, try resizing the browser window and the map should appear. All it needs is a slight resize of the window and it should work as expected (tested on processwire 2.1 with Chrome, Safari, Firefox).
You have to do this every-time you want to use the map (little bit annoying).

I have found this module very useful - would be nice if it was polished off and added as an official field type for Processwire. I'd be happy to discuss sponsoring the development if there was interest.

#15 apeisa

apeisa

    Hero Member

  • Moderators
  • 3,152 posts
  • 1697

  • LocationVihti, Finland

Posted 09 November 2011 - 08:00 AM

I will take a look at this somewhere in not too distant future (before Christmas). Probably small tweaks what is required.

#16 apeisa

apeisa

    Hero Member

  • Moderators
  • 3,152 posts
  • 1697

  • LocationVihti, Finland

Posted 09 November 2011 - 09:00 AM

It seems that if you give your field name "map" then it goes into infinite loop somewhere. Renaming field to something else than "map" fixes this.

#17 neildaemond

neildaemond

    Sr. Member

  • Members
  • PipPipPipPip
  • 123 posts
  • 32

  • LocationHong Kong

Posted 04 December 2011 - 09:06 PM

If you see the gray box, try resizing the browser window and the map should appear. All it needs is a slight resize of the window and it should work as expected (tested on processwire 2.1 with Chrome, Safari, Firefox).
You have to do this every-time you want to use the map (little bit annoying).


Sorry, I didn't notice the reply and ended up working on something else in the meantime, but thanks for the reply, I'll try this out again shortly :)

#18 yellowled

yellowled

    Sr. Member

  • Members
  • PipPipPipPip
  • 200 posts
  • 149

  • LocationEutin, Germany

Posted 07 June 2012 - 08:54 AM

Small issue with this module: It assumes that jQuery is referenced in the <head> of the html, which quite a lot of people (including me :)) don't do. For perfomance reasons (and because it's the HTML5 boilerplates default), I like to reference jQuery before the closing </body>.

I assume it would suffice to edit the FieldtypeGMap.module like this:

$event->return = str_ireplace("</head>", "$css\n</head>", $out);
$event->return = str_ireplace("</body>", "$js\n</body>", $out);

(haven't tested it yet), but that's of course not safe in case of an update to the module. It would be more flexible to have this as an option in the module. Also, the script call in the content area should probably go there also.

I'm fine with adding a Google Map manually if this is not feasible for the module as a general option, I just thought I'd mention it. :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users