Yii 1.1: gmapmultiplot

Plots multiple points on a embedded Google Map
3 followers

GMapMultiplot gained inspiration from the Yii Gmap extension written by Konstantin Mirin. I rewrote the extension to plot multiple locations and upgraded the Javascript file to GMap API v3.

How it works:

  • Accepts an array of ActiveRecord Objects
  • Loops through the array, feeding the address and window data to gmapmultiplot.js
  • gmapmultiplot.js takes the address and sends it to maps.google.com, which returns a geocoded Latitude and Longitude
  • Mapmarker is created with the Lat/Lng and a window(bubble) is created with name, address and phone number
  • For multiple address, the map zooms out and centers so that all MapMarkers are visible.

While the class expects certain attributes, this can easily be edited to fit your needs.

You can view the extension in action by viewing a business profile on Rebates Hampton Roads

Documentation

Requirements

  • Yii 1.1 or above (only tested in 1.1)

Installation

  • Extract the release file under protected/extensions

This extension was originally written to plot a businesses 1 or more locations, but can be easily modified for different scenarios.

If you run into any problems, please feel free to send me an email and I will correct any errors asap. You can find my email address within the class comments.

Usage

See the following code example:

$this->widget('application.extensions.gmapmultiplot.GMapMultiplot', array(
       'id' => 'gmap',//id of the <div> container created
       'label' => $label, //Title for bubble. Used if you are plotting multiple locations of same business
       'address' =>  $array, //Array of AR objects
  ));

If passing the extension a single record, simply wrap the record in an array. This prevents an error while the extension attempts to loop through the records:

$this->widget('application.extensions.gmapmultiplot.GMapMultiplot', array(
       'id' => 'gmap',//id of the <div> container created
       'label' => $label, //Title for bubble. Used if you are plotting multiple locations of same business
       'address' =>  array($array), //Array of AR objects
  ));

For more code examples, please visit the following link Code Sample on Pastebin.com

Change Log

September 29, 2010

  • Initial release.

October 3, 2010

  • Fixed issue with address format being sent to Google Maps. Map would come up blank if attribute "address2" was left empty.

Total 1 comment

#11455 report it
Sharkgr8 at 2013/01/14 03:58pm
A Slight change required in the code

First of all thanks for providing such a great extension. Helps me a lot. But to make it work, I have to debug gmapmultiplot.js. I have to change this line at 106 in gmapmultiplot.js

latlng = new google.maps.LatLng(results[i].geometry.location.b,results[i].geometry.location.c);

to

latlng = new google.maps.LatLng(results[i].geometry.location.Ya,results[i].geometry.location.Za);

to make it work.

Thanks

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: jvickers
  • Category: Web Service
  • Votes: +3
  • Downloaded: 631 times
  • Created on: Sep 29, 2010
  • Last updated: Oct 4, 2010