Code Monkey home page Code Monkey logo

biostall / codeigniter-google-maps-v3-api-library Goto Github PK

View Code? Open in Web Editor NEW
288.0 288.0 199.0 1.82 MB

The library enables you to create a map and overlay multiple markers, polylines, polygons, rectangles, ground overlays and/or circles, all of which are fully customisable. The library also supports showing directions between two points, including the ability to show the textual directions alongside the map too, and marker clustering. The first stages of integration with the Google Places API are available for use too.

Home Page: http://biostall.com/codeigniter-google-maps-v3-api-library

PHP 100.00%

codeigniter-google-maps-v3-api-library's People

Contributors

biostall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codeigniter-google-maps-v3-api-library's Issues

Can I help?

I'm loving your CI library but I have some stuff I want to add to it. If I fork it, are you open to rolling my mods back into the core? (If not, no biggie, but I probably won't go through all of the trouble in that case...)

Change the info window width

I want to change the width of the info window. I see in the google docs that there is a google.maps.InfoWindowOptions object and a maxWidth property but I'm not sure how/where to set this in the library. Any help most appreciated!

Can't have multiple info windows

The infowindow (iw) is only initialised once, so you want multiple ones, the current code doesn't work, although modifying it so that the iw_<map_name> variable is created using the marker index and changing the marker click listener code fixes the problem...

In create_map, remove these lines

    $this->output_js_contents .= '
        var iw_'.$this->map_name.' = new google.maps.InfoWindow(';
    if ($this->infowindowMaxWidth != 0)
    {
        $this->output_js_contents .= '{
            maxWidth: '.$this->infowindowMaxWidth.'
        }';
    }
    $this->output_js_contents .= ');

             ';

Then in add_marker, change it to this...

$marker_output .= '

                    var iw_'.$marker_id.$this->map_name.' = new google.maps.InfoWindow()

        marker_'.$marker_id.'.set("content", "'.$marker['infowindow_content'].'");
                    iw_'.$marker_id.$this->map_name.'.setContent(marker_'.$marker_id.'.get("content"));                            

        google.maps.event.addListener(marker_'.$marker_id.', "click", function(event) {
            iw_'.$marker_id.$this->map_name.'.open('.$this->map_name.', this);
        ';



        if ($marker['onclick']!="") { $marker_output .= $marker['onclick'].'
        '; }
        $marker_output .= '
        });
        ';

                    if ($marker['autoOpen'] == true){
                        $marker_output.= "
                            iw_".$marker_id.$this->map_name.".open('.$this->map_name.', marker_".$marker_id.");";
                    }

Adding text in the circle marker ....

Is there a way of adding text inside the circle marker as shown in the attached image ?

Currently I am using the marker as

$marker = array(
                'infowindow_content' => '('.$i.') ',
                'position' => $latitude.', '.$longitude,
                'title'    => $company,
                'visible'  => true,
            );

which not exactly as what it shows in the map as below.

map-1_img

Perhaps by adding something more in the codes :

$this->load->library('googlemaps');

$config['center'] = '37.4419, -122.1419';
$config['zoom'] = 17;
$this->googlemaps->initialize($config);

$circle = array();
$circle['center'] = '37.4419, -122.1419';
$circle['radius'] = '100';
$this->googlemaps->add_circle($circle);
$data['map'] = $this->googlemaps->create_map();

$this->load->view('view_file', $data);

obtained from : http://biostall.com/demos/google-maps-v3-api-codeigniter-library/circle

demonstrations circle google maps v3 api codeigniter library 2014-02-28 20-37-19

Modify the style for info window

How can i change the style of the infowindow? Im looking everywhere and I just cant find the answer! I think this library is very useful but i really need to change the style of that simple infowindow! Thanks is advance

JS Files

I would like to set where do i can put the script files and the dependencies, not only at the beginning, i would like to add it before close the body tag, and also the order of them.

where or how can i do that?

Find nearest markers

I want to make a website like http://sistemapoliedro.com.br/teste/diogo/v3/
The user can find nearest marker then display route of the way.

I have found the solution in http://stackoverflow.com/questions/4057665/google-maps-api-v3-find-nearest-markers
How to combine the code to biostall google maps API library ?

Here's my controlloer code

$config = array();
$config['center'] = 'makati, philippines';
$config['zoom'] = 'auto';
$config['map_height'] = '800px';
$config['onclick'] = " // What code should I put here ";

$this->googlemaps->initialize($config);
$maps = $this->Web_model->get_maps();

// Display all markers from database
foreach ($maps as $m) {
$marker = array();
$marker['id'] = "".$m->groups."[".$m->id_map."]";
$marker['position'] = $m->lat.','.$m->lng;
$marker['icon'] = base_url().''.$m->icon.'';
$marker['infowindow_content'] = "$m->caption";
$this->googlemaps->add_marker($marker);
}
$data['map'] = $this->googlemaps->create_map();

Thankyou in advance

License Information

I would like to use your library, but I am not finding license information. Is this project proprietary?

Undefined variable: map

Message: Undefined variable: map

How to solve this?

Controller Map.php

defined('BASEPATH') OR exit('No direct script access allowed');

class Map extends CI_Controller {

public function __construct()
{
    parent::__construct();

    $this->m_login->verifica_sessao();
}

public function index()
{
    $this->load->library('googlemaps');
    $config['center'] = '37.4419, -122.1419';
    $config['zoom'] = 'auto';
    $this->googlemaps->initialize($config);
    $marker = array();
    $marker['position'] = '37.429, -122.1419';
    $marker['draggable'] = true;
    $marker['ondragend'] = 'alert(\'You just dropped me at: \' + event.latLng.lat() + \', \' + event.latLng.lng());';
    $this->googlemaps->add_marker($marker);
    $data['map'] = $this->googlemaps->create_map();
    $this->load->view('home', $data);
}

}

I put before the closing tag in the file view header.php:

In the view home.php

I need to config up something of REST?

How to add own places and show them in the google maps on my CI page?

Hello,

I just started using Google Maps Api Library for Codeigniter.
i'm working on an application where people can search based on their postal code and a radius.
i was wondering how to do this with the google maps api. when i turn on Places in my controller i get the nearest places from the lat/lng code. but i want to have a database with postalcodes and an 'own' place. form where the people can search. this is based on their postcode and a radius of about 20km.

Hope someone could help me out with this.

get_lat_long_from_address($address) fails because of sensor parameter

$this->sensor is either true or false as a boolean value. Unfortunately PHP does not nicely convert boolean values to a string. I believe line 2021 should be:

$data_location .= "maps.google.com/maps/api/geocode/json?address=".urlencode(utf8_encode($address))."&sensor=".($this->sensor ? 'true' : 'false');

Currently the workaround appears to be setting "sensor" to a string upon googlemaps initialization config.

Jquery

hi, thank for the nice library. how about to use jquery in this?please help me

Some maps are not dispalying.

Hai friends,
Here I am facing a problem with CI google maps library..
The flow of my program,
1.When user click on the address I am passing that value to the contrler in post method
2.In contrller I am getting the the data with request method.
3.Here I am getting the value successfully
4.After that I am facing aproblem with some address.
5.I am not geeting map for some address.
6.But if I enterd the same address with the in the text box and then submited it. Then It working fine.
Can you please help me where I have mistake.
I am waiting for your reply.

Thanks for your time.

The code is below

Controller function:

function myloaction()
{
            $this->load->library('googlemaps');

    $location = $_REQUEST['mplocation'];
    $config['center'] = $location;
    echo $config['center'];
    $config['zoom'] = 'auto'; 
    $config['map_width'] = '75%';
    $config['map_height'] = '450px';
    $config['places'] = TRUE;
    $config['placesAutocompleteInputID'] = 'mplocation';
    $config['placesAutocompleteBoundsMap'] = TRUE; 
    $this->googlemaps->initialize($config);

    $marker = array();
    $marker['position'] = $location;
    $marker['animation'] = 'DROP';
    $marker['infowindow_content'] = $location;

    $this->googlemaps->add_marker($marker);
    $data['map'] = $this->googlemaps->create_map();
    //print_r($this->googlemaps->create_map()); // Here I am not getting html value. But I am getting marker position values.

    $data['location'] = $location;
    $this->load->view('headerview');
    $this->load->view('usermaplocationview', $data);
    $this->load->view('footerview');
 }

usermaplocationview:

<html>
    <head>
        <?php echo $map['js']; ?>
    </head>
    <body>
       <div>
           <form action="<?php echo base_url();?>maplocation/mylocation" method="post">
              <input name="mplocation" type="text" id="mplocation" name="mplocation" value= "<?php echo $location;?>"placeholder="Enter Your Location" >
          </form>
       </div>
       <?php 
           echo "<center><h4>Location:- ".$location."</h4></center><br>";
           echo "<center>".$map['html']."</center><br>"; 
       ?>
    </body>

Geolocation returning 0,0 for all addresses

I have two CodeIgniter projects both using the same version of your software. Neither project is using an API key. Both take a street address and use Google Maps geolocation to get coordinates.

Both projects worked fine until recently and none of my code has changed. On one project, the geolocation coordinates for ALL addresses are coming back 0,0 with no error message.

$this->load->library('googlemaps');
$location = $data['this_event']['location']; // street address
$geocode = $this->googlemaps->get_lat_long_from_address($location);
$config_map = array(
    'center'    => $location,
    'map_width'  => '375px',
    'map_height' => '300px',
    'map_type'    => 'TERRAIN',
    'zoom'    => 13,
    'ontilesloaded' => 'iw_map.setContent(marker_0.get("content"));'
);
$marker_map = array(
    'position'    => $location,
    'infowindow_content'  => '<div class="infobox">' . $location . '</div>'
);
$this->googlemaps->initialize($config_map);
$this->googlemaps->add_marker($marker_map);
$data['map'] = $this->googlemaps->create_map();

And then in the rendered view, I'm getting latitude and longitude as 0, 0 in the generated JavaScript.

var myLatlng = new google.maps.LatLng(0, 0);

I'm at a loss trying to figure out why it's suddenly failing in one of my two websites.

cutting $map['js'] in two distinct attributes

hi
actualy, you designed CodeIgniter-Google-Maps-V3-API-Library to have 2 outputs in the html page, as following

something would be intersesting :
cut $map['js'] in 2 attributes :

  • $map['head_js'] to set the scripts to load in the header
  • $map['map_js'] to set the needed javascripts to load the map

with that, you can design the html as you wish (ie the javascript not realy needs to be in the header).

Reset coordinates & zoom

Is there a way out to reset the zoom & coordinates of the googlemap to the state when the map was loaded ?

How can I display two Places Input Autocomplete

Hello,
I try to display in my form two Place input fileds autocomplete, but it doesn't work. Only one (the first) input is able to autocomplete. Below the source of code inside my controller

        $config['places'] = TRUE;
        $config['placesAutocompleteInputID'] = 'startCity';
        $config['map_name'] = 'map_one';
        $this->googlemaps->initialize($config);
        $data['map_one'] = $this->googlemaps->create_map();

        $config['places'] = TRUE;
        $config['placesAutocompleteInputID'] = 'endCity';
        $config['map_name'] = 'map_two';
        $this->googlemaps->initialize($config);
        $data['map_two']= $this->googlemaps->create_map();

Multi-Direction

Hi,
I know your library supporting to make multi-direction. Of course with :
$config['directionsWaypointArray'] = array('Position1', 'Position2',);
But, how if I want to pass array variable to change Position1, Position2, ....?
I mean, I want to make it dinamically. Not static.
Thanks

Broken link for google maps clustering markers

http://biostall.com/demos/google-maps-v3-api-codeigniter-library/cluster
The above link is broken, and it's getting the following error:

Failed to load resource: the server responded with a status of 404 (Not Found):
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer_compiled.js

A possible solution would be replacing the broken link for this one:
line: 1143
//google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer_compiled.js
To
cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/src/markerclusterer.js

And
line 1852
gridSize: '.$this->clusterGridSize;
To
imagePath: "https://cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/images/m",
gridSize: '.$this->clusterGridSize;

Thanks

what if the requests more than 2500?

Hai BIOSTALL,

Here I have a question for you that is in the document I saw that the the requests was limited to 2500. What if the requests more than 2500?

And I have one more doubt
Is there any requirment to get API key.?
Can I use your library in my website to show the map of user entered location.

Thank you very much.

Still requesting geocode of location to Google although geocodecaching is turned on

Although in 99% of the cases I'm requesting the same locations and having geocodecaching turned on, I'm still exceeding Googles daily limit very rapidly.

Looking at the function get_lat_long_from_address() it seems like, while geocodecaching is turned on, an address is still send to Google for geocoding even though a record already exists in the geocoding table. Shouldn't this be changed so that this is only done in case no records are returned ($query->num_rows()==0).

Cluster by https

Cluster doesn't work if the page is https, when this library load the script cluster:

<script>http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer_compiled.js</script>

, it is necesary check if https or not in order to pass this variable to the previous code

How to get polygon paths and store it in database and plot back on maps?

Hi @BIOSTALL

First of all thank you very much for such a wonderful library; I went through http://biostall.com/demos/google-maps-v3-api-codeigniter-library/drawingmanager and drew a polygon. But am not sure how to store this polygon on to database and how to retrieve from the database. I went through Google and found out https://developers.google.com/maps/documentation/javascript/examples/polygon-arrays example and also http://jsfiddle.net/doktormolle/EdZk4/light/.

But in vain; we are unable to add these event listeners on to the map.....

Error

Oops! There is something wrong.
This page does not load Google Maps properly. View the JavaScript console for technical details.

How to resolve this

It is posible to use isLocationOnEdge with this Library

I need to determine whether a point falls on or near a polyline, or on or near the edge of a polygon, within a specified tolerance in meters. I know that other librarys have the method isLocationOnEdge. BIOSTALL Has something to do this job.

getting marker new position on ondragend event

hi
i want to update position in the database when someone is dragging the marker .
i think i have to send a ajax request on "ondragend" event and send the new position to my CI controller .

but how can i get the new position on "ondragend" event ?

$this->load->library('googlemaps');
$this->googlemaps->initialize($config);
$marker = array();
$marker['draggable'] = true ;
$marker['ondragend'] = "UpdatePosition(lt , lg )" ;
$this->googlemaps->add_marker($marker);
$data['map'] = $this->googlemaps->create_map();

lt and lg are latitude and longitude coordinates

$marker['ondragend'] = "UpdatePosition(lt , lg )" ;

google map api - $marker['infowindow_content'] html allowed?

I want to know whether can i add html form submission to the marker added in the maps. my logic is: when the user click the marker in the map it opens a info window where i need html form to be placed with submit button and options. Please help me how to do that.

Awaiting for the reply.

Codeigniter Google Maps API V3 Toggle Markers

I am using codeigniter and this library file to display the google map settings:

https://github.com/BIOSTALL/CodeIgniter-Google-Maps-V3-API-Library/blob/master/application/libraries/Googlemaps.php

In my header the js is displayed as this:

and my data is stored in a database and pulled in using the contollers and models:

model:

function get_coordinates() {
$return = array();
$query = $this->db->get('markers');

    if ($query->num_rows()>0) {
        foreach ($query->result() as $row) {
        array_push($return, $row);
        }
    }
return $return;
} 

Controller:

public function index() {

    $this->load->library('googlemaps');
    $this->load->model('home_model', '', TRUE);

    $this->googlemaps->initialize();

    $coords = $this->home_model->get_coordinates();


    foreach ($coords as $coordinate) {
        if($coordinate->type == "restaurant"){
            $image = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|FF0000|000000';
        }

        if($coordinate->type == "bar"){
            $image = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=B|FFFFFF|000000';
        }

        $marker = array('id'=> $coordinate->type, 'position' => $coordinate->lat.','.$coordinate->lng, 'icon' => $image, 'infowindow_content' =>$coordinate->address);


        $this->googlemaps->add_marker($marker);

    }

    $data = array();

    $data['map'] = $this->googlemaps->create_map();

    $data['page_title'] = "Home";
    $data['content'] = "home";  
    $this->load->view('template', $data);

}
I am trying to add a toggle feature in the view so if you click the bar button, the bar markers show and so on. I am having difficulty grabbing the marker id and types to even start this due to the js being stored in a variable and when i relocate the js to a file it keeps refreshing so it removes my code.

Does anyone have any idea with this library to add a toggle feature in as i cant even do a click event and alert anything out!

I am attempting something similar to this without the sidebar: http://www.geocodezip.com/v3_MW_example_categories.html

Just unsure of where and how to edit and keep what i write as the js variable keeps changing it!

Thanks!

morris.js (Morris Line&Bar charts) on "infowindow_content"

Can I show Morris charts on "infowindow_content ($marker['infowindow_content'] = '1 - Hello World!';)" ? Here is the scenario;
1.) User clicked the marker
2.) infowindow_content opened and it consists of Morris chart

Are there any way to do it?

Thanks...

Ahmet

my map output not showing street

i cannot understand why my map output not showing the street or any info of the name of the street ... and it just showing blank.. it just there's my marker alone...... ?

Custom MULTIPLE Markers to toggle on Map

I am using your library for a website which is fantastic. After reading your documentation i am still a little confused on how to create multiple icon markers to integrate into the library.

In the library file i can see where to add the custom marker: $marker['icon'] = ''; but in my database where my information is stored i have a field name called type and either say 'bars' and 'restaurants' for example. I am after to assign each type a custom marker and display on the map, which users are then able to toggle using buttons.

The marker type is brought in as follows:

$marker = array('id'=> $coordinate->type ---other elements---);

Is this possible to do using your library?

Thanks!

can i use your library for another framework such as laravel ?

hi... i used to be using your library in the CI framework, but i eager to learn new framework laravel. as far i know your library is very easy to use but i cannot find same as yours for laravel package (library).

i want to know is this library framework independent or can i use it with another framework ?

thanks bro... :)

Current Position to Direction

Hello,

Is there a way to get my current location (Geolocation) in the directions mode ?
So i can get the route from my current location to my destination ?
In the $config['directionsStart'] var

Greets,
Marco.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.