I am currently working on a website that is based on bike routes. What basically happens is our client goes out and rides the route tracking the route with his GPS devise. He then downloads this GPS info into MemoryMaps and adjusts the route points as necessary. This information is then exported from MemoryMaps into a GPX file. The GPX file is then uploaded into our custom built backend along with some route information and a description and this route is then listed as a route. The first latitude and longitude imported from the GPX file is saved as the starting point and so an overview map can be shown of all the routes. When you click on one of the route starting points you get a little overview of the route and you can then click to view the full route page.
I am using Codeigniter for this project. I am obsessed with Codeigniter since I was introduced to it by @boxedfish. Its taken me a long time to move away from my own framework, but the move has been well worth it. There is an amazing PHP Google Maps API class which I have used in the past and I was about to get started on creating a Codeigniter library using this class when it crossed my mind to do a quick search in Google for one already built. Wise move! Google Maps API V3 Library already exists thanks to the good people at in-the-attic.co.uk.
Adding an overview map with a number of markers was one of the easiest implementations of Google maps I have ever done… however I got a little stuck when it came to the route information pages where I wanted to show the route points using polylines. A simple enough task!
I fired up the documentation (which is part of the original php class not the library by in-the-attic.co.uk)
$this->gmap->addPolylineByCoordsArray($poly_array,false,'#FF0000', '6', '0.5');
This should have done the trick. I simply get all the coordinates of my route, put them in an array and bing, bang bosh! I tried everything under the sun to get this to work but I could not get the polylines to display on the map, every time I tried to load the page the map would not load. I knew I was getting the information in the array but something was not right. I made a cry of help to twitter but nothing came back… I did what every good developer should do, I went away and worked on something else! Then it hit me, why not just open up the class file and look at the function that processes the $poly_array and see what format it should be in. It was then I realised that I was assuming that everyone called latitude ‘lat’ and longitude ‘lng’. In fact it was expecting ‘long’!
So for anyone else out there was is having problems, the correct array format for addPolylineByCoordsArray is:
$poly_array = array('lat' => $my_lat, 'long' => $my_lng);