Global Positioning System was developed by the United States' Department of Defense. It uses between 24 and 32 Medium Earth Orbit satellites that transmit precise microwave signals. This enables GPS receivers to determine their current location, time and velocity. The GPS satellites are maintained by the United States Air Force.
GPS is often used by civilians as a navigation system. On the ground, any GPS receiver contains a computer that "triangulates" its own position by getting bearings from at least three satellites. The result is provided in the form of a geographic position - longitude and latitude - to, for most receivers, within an accuracy of 10 to 100 meters. Software applications can then use those coordinates to provide driving or walking instructions.
Getting a lock on by the GPS receivers on the ground usually takes some time especially where the receiver is in a moving vehicle or in dense urban areas. The initial time needed for a GPS lock is usually dependent on how the GPS receiver starts. There are three types of start - hot, warm and cold.
The hot start is when the GPS device remembers its last calculated position and the satellites in view, the almanac used (information about all the satellites in the constellation), the UTC Time and makes an attempt to lock onto the same satellites and calculate a new position based upon the previous information. This is the quickest GPS lock but it only works if you are generally in the same location as you were when the GPS was last turned off.
The warm start is when the GPS device remembers its last calculated position, almanac used, and UTC Time, but not which satellites were in view. It then performs a reset and attempts to obtain the satellite signals and calculates a new position.
The receiver has a general idea of which satellites to look for because it knows its last position and the almanac data helps identify which satellites are visible in the sky. This takes longer than a hot start but not as long as a cold start.
And finally – the cold start is when the GPS device dumps all the information, attempts to locate satellites and then calculates a GPS lock. This takes the longest because there is no known information.
The GPS receiver has to attempt to lock onto a satellite signal from any available satellites, basically like polling, which takes a lot longer than knowing which satellites to look for. This GPS lock takes the longest.
In an attempt to improve lock times, cellphone manufacturers and operators have introduced the Assisted GPS technology, which downloads the current ephemeris for a few days ahead via the wireless networks and helps triangulate the general user’s position with the cell towers thus allowing the GPS receiver to get a faster lock at the expense of several (kilo)bytes.
Until now, interfacing to both satellite and terrestrial communication networks was a difficult and time-consuming task involving multiple pieces of equipment, differing message formats and brute force routing - all at a high cost and increased time-to-market. The SureLinx 8100 series terminals with dual-mode satellite/GPRS capability are designed to save time and simplify application development for mobile asset tracking, logistics and security applications.
The SureLinx communication terminals operate in a similar manner to the satellite-only solutions. When out of cellular zones, the SureLinx use the GPS satellites to acquire position information and Inmarsat satellites to send and receive data. The data is then directed to the Solution Provider via Land Earth Stations (LES) and SkyWave Network Operation Center. If the SureLinx is in a region where there is cellular coverage, it automatically switches to the available network and sends data to the Solution Provider directly.
system-picture-surelinx
surelinx-8100
SureLinx8100
Engineered for dual-mode satellite/GPRS applications
surelinx-8100c
SureLinx8100c
All the same features of SureLinx 8100 with additional on-board computer and CANbus interface for sophisticated applications.
On 9th January, 2007, Apple officially launched the iPhone, and the world of user
interface design shifted. While tablet PCs had been around for a while, the iPhone was
the first device to give so many people a portable touchscreen, and people loved it. Just
over a year later, Google and the Open Handset Alliance announced Android which in
many ways is the direct competitor to iPhone.
What is it about touchscreen phones that we love? The answer is simple—feedback.
Touchscreens offer a way to directly manipulate on-screen objects, which in the past had
to be driven through a keyboard, mouse, joystick, or other input device. The touchscreen
model of direct manipulation has a large impact on the way we think about our user
interfaces as developers, and changes the expectations a user has for the application.
Touchscreen devices require us to stop thinking in terms of forms, and start thinking
about object-oriented user interfaces.
Android is used as the primary operating system for a rapidly expanding range of
consumer electronics, including:
• Smartphones
• Netbooks
• Tablets
• Some desktop systems
While all of these devices have different purposes and specifications, all of them run
Android. This is unlike many other operating environments which are almost always
have a special purpose. The services and the APIs they provide to developers generally
reflect their target hardware. Android on the other hand makes the assumption that a
single application may be required to run on many different types of devices, with very
different hardware capabilities and specifications, and makes it as easy as possible for
developers to handle the differences between these devices simply and elegantly.
New challenges
As Android and the touchscreen devices it powers become increasingly common, they
will bring a new set of challenges to user interface design and development:
• You generally don't have a mouse
• You may have more than one pointing device
• You often don't have a keyboard
• Any keyboard that does exist may be a software keyboard
• A software keyboard may consume some of your application's screenspace
The software keyboard reduces the amount of screen space available to your application,
and in much the same vein, if there is a hardware keyboard present it may or may not
always be exposed to the user. Therefore, not only are different Android devices
different, but they may also appear to change features while your application is running.
The rule of finger
Most Android devices have touchscreens (although this is not a requirement). The first
restriction placed on any touchscreen user interface is the size of the human forefinger,
which of course varies widely from one person to another. If a widget is too small on the
screen, it won't be clear what the user is trying to touch. You'll notice that most Android
widgets take up plenty of space, and have more than the normal amount of padding
around them. On a touchscreen device, you can't rely on pixel-perfect precision. You
need to make sure that when the user touches a widget, they make contact, and they don't
accidentally touch another widget.
The magic touch
Another impact touchscreens have on user interface design is that an application and all
the widgets that it uses must be entirely self-explanatory (even more than usual). Far too
often, we substitute good user interface planning and design with a roll-over or tooltip to
indicate a widget's function. On a touchscreen device, there is no mouse or pointing
device. The first interaction it has with the user is when they touch it, and they will
expect something to happen.
A touchy subject
Most Android devices have a touchscreen, but it's not a requirement.
The quality of a touchscreen also varies wildly from device to device.
The category of touchscreens and their capabilities will also vary from
one device to the next, depending on the intended use of the device and
often its intended market segment.
A smaller view on the world
Most Android devices are small, and as a result have smaller screens and generally fewer
pixels than a normal PC or laptop. This lack of size limits the size of the widgets.
Widgets must be big enough to touch safely, but we also need to pack as much
information onto the screen as possible. So don't give your users information that they
don't want, and also avoid asking them for information you don't need.
Classic user interface principals
Here are some core guidelines which every user interface should follow. These guidelines
are what will keep your users happy, and ensure your application is successful.
Throughout the rest of the book, we'll be walking through these guidelines with practical
examples of improvements that can be made to a user interface.
Consistency
This is the cornerstone of good user interface design. A button should look like a button.
Make sure that the layout of each screen has a relationship with every other screen in
your application. People often mistake this principle for "stick to the platform look and
feel". Look and feel is important, consistency mostly applies to the layout and overall
experience of the application, rather than the color scheme.
Recycling your interface
The easiest way to maintain a consistent user interface, is to recycle as much of it as
possible. At first glance, this suggestion looks merely like a "good object-oriented"
practice. However, a closer look will reveal ways to reuse graphical widgets in ways you
hadn't thought of. By changing the visibility of various widgets, or you can reuse an edit
screen to view list items of the intended type.
Simplicity
This is especially important in a phone-based application. Often, when a user encounters
a new application, it's because they are looking for something. They may not have the
time (or more often patience) to learn a new user interface. Make sure that your
application asks for as little as possible, and guides the user to the exact information they
want in as few steps as possible.
The Zen approach
Generally, when you are using a mobile device, your time is limited. You may also be
using an application in less-than-ideal circumstances (perhaps, in a train). The lesser
information a user needs to give an application, and the lesser they need to absorb from it,
the better. Stripping away options and information also leads to a shorter learning-curve.
Android's hidden menu
A very useful feature of Android is the hidden menu structure. The menu is only visible
when the user presses the "Menu" button, which would generally mean, they're looking
for something that isn't currently on the screen. Typically, a user shouldn't need to open a
menu. However, it's a good way of hiding advanced features until they are needed.
Feedback
Feedback is what makes a touchscreen device exciting. When you drag an object, it sticks
to your finger across the screen until you let go of it. When the users puts their finger on
your application, they expect some reaction. However, you don't want to get in their
way—instead of showing an error message when they touch a button, disable the button
until it's valid to use, or don't show it at all.
Location and navigation
When you're in a place you've never been to previously, it's easy to get disoriented, or
lost. The same is true for a piece of software. Just because the application makes sense to
you, the developer, it doesn't mean it seems logical to your user. Adding transition
animations, breadcrumbs, and progress gauges help the user to identify where in the
application they are, and what's happening.
The road to recovery
A common way to tell users that something is wrong on a desktop application, or on the
web is to open an error dialog. On a mobile device, people want smoother use of an
application. While in a normal application you may inform the user that they selected an
invalid option, in a mobile application, you generally want to make sure they can't select
that option in the first place. Also, don't make them scroll through huge lists of options.
Instead, allow them to filter through the list using an auto-complete or something similar.
When something goes wrong, be nice, and be helpful—don't tell the user, "I couldn't find
any flights for your search". Instead tell them, "There were no available flights for your
search, but if you're prepared to leave a day earlier, here is a list of the available flights".
Always make sure your user can take another step forward without having to go "Back"
(although the option to go backwards should always exist).
The Android way
The Android platform is in many ways similar to developing applications for the web.
There are many devices, made by many manufactures, with different capabilities and
specifications. Yet as a developer, you will want your users to have the most consistent
experience possible. Unlike a web browser, Android has built-in mechanisms for coping
with these differences, and even leveraging them.
We'll be looking at Android from the point of view of a user rather than having a purely
development-centric approach. We'll cover topics such as:
• What user interface elements Android provides
• How an Android application is assembled
• Different types of Android layouts
• Presenting various types of data to the user
• Customising of existing Android widgets
• Tricks and tools to keep user interfaces looking great
• Integration between applications
We're about to take a jump into building user interfaces for Android devices—all
Android devices, from the highest speed CPU to the smallest screen.
Google have been hosting several JavaScript libraries for a while now on Google Code and there are several advantages to loading it from them instead of from your server. It saves on bandwidth, it'll load very quickly from Google's CDN and most importantly it'll already be cached if the user has visited a site which delivers it from Google Code.
This makes a lot of sense. How many sites out there are serving up identical copies of jQuery that aren't getting cached? It's easy to do too...
view plaincopy to clipboardprint?
Or, you can just include a direct reference like this...
view plaincopy to clipboardprint?
Full instructions here
2. Use a cheat sheet
Not just a jQuery tip, there are some great cheat sheets out there for most languages. It's handy having every function on a printable A4 sheet for reference and luckily these guys have produced a couple of nice ones..
OK, a general JavaScript tip here. But any big project that uses lots of jQuery probably uses lots of plugins (this site uses easing, localScroll, lightbox and preload) so it's usually applicable.
Browsers can't load scripts concurrently (well, most can't, yet), which means that if you've got several scripts downloading one at a time then you're really slowing down the loading of your page. So, assuming the scrips are being loaded on every page then you should consider combining them into one long script before deploying.
Some of the plugins will already be minified, but you should consider packing your scripts and any that aren't already. It only takes a few seconds. I'm personally a fan of Packer by Dean Edwards
4. Use Firebug's excellent console logging facilities
If you haven't already installed Firebug then you really should. Aside from many other useful features such as allowing you to inspect http traffic and find problems with your CSS it has excellent logging commands that allow you to easily debug your scripts.
Here's a full explanation of all of it's features
My favourite features are "console.info", which you can use to just dump messages and variables to the screen without having to use alert boxes and "console.time" which allows you to easily set up a timer to wrap a bunch of code and see how long it takes. They're all really easy to use too...
view plaincopy to clipboardprint?
console.time('create list');
for (i = 0; i < 1000; i++) { var myList = $('.myList'); myList.append('This is list item ' + i); } console.timeEnd('create list'); In this instance I've deliberately written some very inefficient code! In the next few tips I'll show you how we can use the timer to show some improvements which can be made. 5. Keep selection operations to a minimum by caching jQuery selectors are awesome. They make selecting any element on the page incredibly simple, but internally they have to do a fair amount of work and if you go mad with them you might find things starting to get pretty slow. If you're selecting the same element time and time again (in a loop for example) then you can just select it once and keep it in memory while you manipulate it to your heart's content. Take the following example where we add items to an unordered list using a loop. view plaincopy to clipboardprint? for (i = 0; i < 1000; i++) { var myList = $('.myList'); myList.append('This is list item ' + i); } That takes 1066 milliseconds on my PC in Firefox 3 (imagine how long it would IE6!), which is pretty slow in JavaScript terms. Now take a look at the following code where we use the selector just once. view plaincopy to clipboardprint? var myList = $('.myList'); for (i = 0; i < 1000; i++) { myList.append('This is list item ' + i); } That only takes 224 milliseconds, more than 4x faster, just by moving one line of code. 6. Keep DOM manipulation to a minimum We can make the code from the previous tip even faster by cutting down on the number of times we insert into the DOM. DOM insertion operations like .append() .prepend() .after() and .wrap() are relatively costly and performing lots of them can really slow things down. All we need to do is use string concatenation to build the list and then use a single function to add them to your unordered list like .html() is much quicker. Take the following example... view plaincopy to clipboardprint? var myList = $('#myList'); for (i=0; i<1000; i++){ myList.append('This is list item ' + i); } On my PC that takes 216 milliseconds , just over a 1/5th of a second, but if we build the list items as a string first and use the HTML method to do the insert, like this.... view plaincopy to clipboardprint? var myList = $('.myList'); var myListItems = ''; for (i = 0; i < 1000; i++) { myListItems += '
This is list item ' + i + '
';
}
myList.html(myListItems);
That takes 185 milliseconds, not much quicker but that's another 31 milliseconds off the time.
7. Wrap everything in a single element when doing any kind of DOM insertion
OK, don't ask me why this one works (I'm sure a more experienced coder will explain).
In our last example we inserted 1000 list items into an unordered list using the .html() method. If we had have wrapped them in the UL tag before doing the insert and inserted the completed UL into another tag (a DIV) then we're effectively only inserting 1 tag, not 1000, which seems to be much quicker. Like this...
view plaincopy to clipboardprint?
var myList = $('.myList');
var myListItems = '
';
for (i = 0; i < 1000; i++) { myListItems += '
This is list item ' + i + '
';
}
myListItems += '
';
myList.html(myListItems);
The time is now only 19 milliseconds, a massive improvement, 50x faster than our first example.
8. Use IDs instead of classes wherever possible
jQuery makes selecting DOM elements using classes as easy as selecting elements by ID used to be, so it's tempting to use classes much more liberally than before. It's still much better to select by ID though because jQuery uses the browser's native method (getElementByID) to do this and doesn't have to do any of it's own DOM traversal, which is much faster. How much faster? Let's find out.
I'll use the previous example and adapt it so each LI we create has a unique class added to it. Then I'll loop through and select each one once.
view plaincopy to clipboardprint?
// Create our list
var myList = $('.myList');
var myListItems = '
';
for (i = 0; i < 1000; i++) { myListItems += '
This is a list item
';
}
myListItems += '
';
myList.html(myListItems);
// Select each item once
for (i = 0; i < 1000; i++) { var selectedItem = $('.listItem' + i); } Just as I thought my browser had hung, it finished, in 5066 milliseconds (over 5 seconds). So i modified the code to give each item an ID instead of a class and then selected them using the ID. view plaincopy to clipboardprint? // Create our list var myList = $('.myList'); var myListItems = '
';
for (i = 0; i < 1000; i++) { myListItems += '
This is a list item
';
}
myListItems += '
';
myList.html(myListItems);
// Select each item once
for (i = 0; i < 1000; i++) { var selectedItem = $('#listItem' + i); } This time it only took 61 milliseconds. Nearly 100x faster. 9. Give your selectors a context By default, when you use a selector such as $('.myDiv') the whole of the DOM will be traversed, which depending on the page could be expensive. The jQuery function takes a second parameter when performing a selection. jQuery( expression, context ) By providing a context to the selector, you give it an element to start searching within so that it doesn't have to traverse the whole of the DOM. To demonstrate this, let's take the first block of code from the tip above. It creates an unordered list with 1000 items, each with an individual class. It then loops through and selects each item once. You'll remember that when selecting by class it took just over 5 seconds to select all 1000 of them using this selector. view plaincopy to clipboardprint? var selectedItem = $('#listItem' + i); I then added a context so that it was only running the selector inside the unordered list, like this... view plaincopy to clipboardprint? var selectedItem = $('#listItem' + i, $('.myList')); It still took 3818 milliseconds because it's still horribly inefficient, but that's more than a 25% speed increase by making a small modification to a selector. 10. Use chaining properly One of the coolest things about jQuery is it's ability to chain method calls together. So, for example, if you want to switch the class on an element. view plaincopy to clipboardprint? $('myDiv').removeClass('off').addClass('on'); If you're anything like me then you probably learned that in your first 5 minutes of reading about jQuery but it goes further than that. Firstly, it still works across line breaks (because jQuery = JavaScript), which means you can write neat code like this... view plaincopy to clipboardprint? $('#mypanel') .find('TABLE .firstCol') .removeClass('.firstCol') .css('background' : 'red') .append('This cell is now red');
Making a habit of using chaining automatically helps you to cut down on your selector use too.
But it goes further than that. Let's say that you want to perform several functions on an element but one of the first functions changes the element in some way, like this...
We've selected a table, drilled down to find cells with a class of "firstColumn" and coloured them in red.
Let's say we now want to colour all the cells with a class of "lastColumn" blue. Because we've used the find() funciton we've filtered out all the cells that don't have a class of "firstColumn" so we need to use the selector again to get the table element and we can't continue chaining, right? Luckily jQuery has an end() function which actually reverts back to the previous unaltered selection so you can carry on chaining, like this...
It's also easier than you might think to write your own jQuery function which can chain. All you have to do is write a function which modifies an element and returns it.
When I first started using jQuery I loved the fact that it was easy to use the pre-defined animations like slideDown() and fadeIn() to get some really cool effects incredibly easy. It's easy to take things further though because jQuery's animate() method is very easy to use and very powerful. In fact, is you look at the jQuery source code you'll see that internally those methods are just shortcuts which use the animate() function.
The animate() method simply takes any CSS style and smoothly transitions it from one value to another. So, you can change the width, height, opacity, background-color, top, left, margin, color, font-size, anything you want.
This is how easy it is to animate all your menu items grow to 100 pixels high when you roll over them.
Unlike other jQuery functions, animations are automatically queued, so if you want to run a second animation once the first is finished then just call the animate method twice, no callback necessary.
You can animate any property that's numeric. You can also download plugins to help you animate properties that aren't, like colors and background colors
12. Learn about event delegation
jQuery makes it easier than ever to attach events to elements in the DOM unobtrusively, which is great, but adding too many events is inefficient. Event delegation allows you to add less events to achieve the same result in many situations. The best way to illustrate this is with an example...
A simple function which turns cells in a table red when you click on them. Let's say that you've got a grid with 10 columns and 50 rows though, that's 500 events bound. Wouldn't it be neater if we could just attach a single event to the table and when the table is clicked have the event handler work out which cell was clicked before turning it red?
Well that's exactly what event delegation is and it's easy to implement...
view plaincopy to clipboardprint?
$('#myTable').click(function(e) {
var clicked = $(e.target);
clicked.css('background', 'red');
});
'e' contains information about the event, including the target element that actually received the click. All we have to do is inspect it to see which cell was actually clicked. Much neater.
Event delegation has another benefit. Normally, When you bind a handler to a collection of elements it gets attached to those elements and those elements only. If you add new elements to the DOM which would have been matched by the selector then they don't have the event handler bound to them (are you following me?) then nothing will happen.
When using event delegation you can add as many matching elements to the DOM as you like after the event is bound and they work too.
13. Use classes to store state
This is the most basic way of storing information about a block of html. jQuery is great at manipulating elements based upon their classes, so if you need to store information about the state of an element then why not add an extra class to store it?
Here's an example. We want to create an expanding menu. When you click the button we want the panel to slideDown() if it's currently closed, or slideUp() if it's currently open. We'll start with the HTML
view plaincopy to clipboardprint?
click me
Menu item 1
Menu item 2
Menu item 3
Very simple! We've just added an extra class to the wrapper div which serves no other purpose other than to tell us the state of the item. So all we need is a click event handler which performs slideUp() or slideDown() on the corresponding panel when the button is clicked.
view plaincopy to clipboardprint?
$('.button').click(function() {
var menuItem = $(this).parent();
var panel = menuItem.find('.panel');
if (menuItem.hasClass("expanded")) {
menuItem.removeClass('expanded').addClass('collapsed');
panel.slideUp();
}
else if (menuItem.hasClass("collapsed")) {
menuItem.removeClass('collapsed').addClass('expanded');
panel.slideDown();
}
});
That's a very simple example, but you can add extra classes for storing all sorts of information about an element or HTML fragment.
However, in all but simple cases it's probably better to use the next tip.
14. Even better, use jQuery's internal data() method to store state
It's not very well documented for some reason but jQuery has an internal data() method which can be used to store information in key/value pairs against any DOM element. Storing a piece of data is as simple as this...
view plaincopy to clipboardprint?
$('#myDiv').data('currentState', 'off');
We can amend the example from the previous tip. We'll use the same HTML (with the "expanded" class removed) and use the data() function instead.
view plaincopy to clipboardprint?
$('.button').click(function() {
var menuItem = $(this).parent();
var panel = menuItem.find('.panel');
I'm sure you'll agree this is much neater. For more information about data() and removeData(), see this page...
jQuery internals
15. Write your own selectors
jQuery has loads of built-in selectors for selecting elements by ID, class, tag, attribute and many more. But what do you do when you need to select elements based upon something else and jQuery doesn't have a selector?
Well, one answer would be to add classes to the elements from the start and use those to select them, but it turns out that it's not hard to extend jQuery to add new selectors.
$('.box:over100pixels').click(function() {
alert('The element you clicked is over 100 pixels high');
});
The first block of code creates a custom selector which finds any element that is more than 100 pixels tall. The second block just uses it to add a click handler to all those elements.
I won't go into any more detail here but you can imagine how powerful this is and if you search google for "custom jquery selector" you'll find loads of great examples.
16. Streamline your HTML and modify it once the page has loaded
The title might not make a lot of sense but this tip can potentially neaten up your code, reduce the weight and download time of your page and help your SEO. Take the following HTML for example...
view plaincopy to clipboardprint?
This is field number 1
This is an error message
This is field number 2
This is an error message
That's an example of how a form might be marked up, modified slightly for illustrative purposes. I'm sure you'll agree it's pretty ugly and if you had a long form you'd end up with a fairly long ugly page. It's be nicer if you could just put this in your HTML.
view plaincopy to clipboardprint?
This is field 1
This is field 2
This is field 3
This is field 4
This is field 5
All you have to do is a bit of jQuery manipulation to add all the ugly HTML back in. Like this...
It's not always advisable to do this, you'll get a bit of a flash as the page loads, but in certain situations where you've got a lot of repeated HTML it can really reduce your page weight and the SEO benefits of reducing all your repeated extraneous markup should be obvious.
17. Lazy load content for speed and SEO benefits
Another way to speed up your page loads and neaten up the HTML that search spiders see is to lazy load whole chunks of it using an AJAX request after the rest of the page has loaded. The user can get browsing right away and spiders only see the content you want them to index.
We've used this technique on our own site. Those purple buttons at the top of the page drop down 3 forms, directions and a google map, which was doubling the size of our pages. So, we just put all that HTML in a static page and use the load() function to load it in once the DOM was ready. Like this...
view plaincopy to clipboardprint?
$('#forms').load('content/headerForms.html', function() {
// Code here runs once the content has loaded
// Put all your event handlers etc. here.
});
I wouldn't use this everywhere. You have to consider the trade offs here. You're making extra requests to the server and portions of your page might not be available to the user right away, but used correctly it can be a great optimization technique.
18. Use jQuery's utility functions
jQuery isn't just about flash effects. The creator has exposed some really useful methods which fill a few gaps in JavaScript's repertoire.
http://docs.jquery.com/Utilities
In particular, browser support for certain common array functions is patchy (IE7 doesn't even have an indexOf() method!). Jquery has methods for iterating, filtering, cloning, merging and removing duplicates from Arrays.
Other common functions that are difficult in Javascript include getting the selected item in a drop down list. In plain old JavaScript you'd have to get the
There are many times I want to leverage jQuery’s strengths to create a custom Google Maps mashup. In this tutorial, I will walk you through how to get started using jQuery inside the Google Maps environment. I will assume nothing, and explain each piece in detail.
View Final Demo If you are already familiar with Google Maps API, skip to step #5, or so.
Make sure to replace YOUR_API_KEY_HERE with your API key. By using the Google AJAX Libraries API, it allows you to load the JavaScript libraries you need right from Google’s servers. This increases the chance that your users will be able to load the scripts faster from their browser cache, as well as shuffle the jQuery script loading off your server.
Step #3: Create the Google Map
To create our Google Map, we need to create a container div and use CSS to give it a width and a height.
id="map">
Use the GMap2 function to make a map instance. Then, set the center of the map. I wrapped this code block in jQuery’s document ready function so that the code is run after the page has loaded.
$(document).ready(function(){
var map = new GMap2(document.getElementById(‘map’));
var burnsvilleMN = new GLatLng(44.797916,-93.278046);
map.setCenter(burnsvilleMN, 8);
});
Here, I used Burnsville, MN’s latitude and longitude because it is where I live right now. There are many ways to get the latitude and longitude of an address, like this simple service by iTouchMap.
The second parameter for setCenter is the zoom level, which is a number. I set the zoom level to"8"here because it is about in the middle.
At this point we should have a simple map.
var point = new GLatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random());
marker = new GMarker(point);
map.addOverlay(marker);
markers[i] = marker;
}
Note that I added a markers array to the example code. This will be used in the next step.
Step #5: Loop Through Markers and Add Basic Click Event to Markers
In this step, we start to use jQuery and Google Maps together. We want to be careful to use Google Map’s built-in API as much as possible, leaving jQuery only for what it is best at.
Let’s take that array of markers and loop through them with jQuery’s each method.
$(markers).each(function(i,marker){
GEvent.addListener(marker,"click", function(){
map.panTo(marker.getLatLng());
});
});
Inside the loop, let’s use Google Maps’s GEvent namespace to attach a click event to each marker. Then, we will add a panTo behavior to center the map on the marker. marker.getLatLng(); returns the latitude and longitude of the marker, while map.panTo(GLatLng) allows us to center the map on that latitude and longitude.
Step #6 – Make a Clickable List of Markers
Let’s add a clickable list next to the map. Insert a ul.
<ul id="list"></ul>
Then let’s style it up a bit by floating the map left and float our list element next to it. We also want to add a hover effect to the list items to give visual feedback to the user that they can click on each item in the list.
Here I am just setting the content to"Point (the count)", adding that same panTo action from before, then appending the list item to our list.
Step #7 – Add a Custom Message
When I create a Google Maps mashup, I usually want to replace the built-in info window with something custom. With jQuery, we can add any arbitrary HTML in place of the info window. This is great when you want complete control over what the info window looks like.
We have to place the message div inside the map. To do this, we can use jQuery to append it to an object. The map view is seperated into panes. Each pane is a div layered on top of the other. To get the div object that we want to attach our message div to, we can use map.getPane(PANE). The G_MAP_FLOAT_SHADOW_PANE is the layer that I find works best for attaching custom messages.
To show the message div in place of the info window, we need to separate the click action into a separate function. Replace the map.panTo(marker.getLatLng(); with displayPoint(marker, i);, a call to the new displayPoint function shown below.
functiondisplayPoint(marker, i){
map.panTo(marker.getPoint());
var markerOffset = map.fromLatLngToDivPixel(marker.getPoint());
We put the panTo action in our new function. Then the magic function here is the map.fromLatLngToDivPixel(GLatLng); which converts the latitude/longitude of the marker into a pixel on the map div.This returns aobject containing x (amount of pixels from the left of the map) and y (amount of pixels from the top of the map).
Final Step #8 – Add Some Spice
To finish up, we will add an event when the map stops panning. We can do this by attaching the"movend"event map object. This way, after panning to the marker you’ve clicked on we can use jQuery’s fadeIn method to add some spice.
functiondisplayPoint(marker, index){
$("#message").hide();
var moveEnd = GEvent.addListener(map,"moveend", function(){
var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
There you have it. We’ve come a long ways by adding our own custom click event, a clickable list and a custom info window. In the next tutorial, I’ll show you how to store and retrieve points with a server-side language.
Submitted by birdwingfx on October 16, 2009 - 9:22pm
For people that want to add Google maps to their website, but don't want their website to be bogged down with features they don't need.
Jquery GPS is a lightweight and simple solution to all your Google Map needs.
Add inputs for addresses by simply adding default or custom ID's.
You can use any element to trigger the event! So it doesn't need to be embedded inside a form.
The default ID's make it easy to create an application that will give directions and a highlighted map right on your website!
Thats it! By using the default ID's you have just created a driving directins application for your website!. All thats left is to load the google maps API and initiate the plugin using Jquery.
First In order to use The Google Maps API you must have an API key which you can get Here. Then you have to load jQuery the google maps API and the plugin:
Because there is NO default ID for what Div tag the MAP will be in we use this initiate the plugin:
As you can see here the div with the id="map" is where the google map will appear.
Thats it! now anyone can get directions from your website.
There are more features like setting where the map first is when it loads, the zoom level, and some other features that would be good for a business. Hopefully I will finish the documentation soon so that you can take advantage of these features!
jQuery GPS is a jQuery plugin for people that want to add Google maps to their website, but don't want their website to be bogged down with features they don't need.
Jquery GPS is a lightweight and simple solution to all your Google Map needs. Add inputs for addresses by simply adding default or custom ID's. You can use any element to trigger the event! So it doesn't need to be embedded inside a form.
The default ID's make it easy to create an application that will give directions and a highlighted map right on your website!
jQuery GPS also has the ability for you to select the place the map shows when it first loads, and to open a toolip and load a graphic image on that starting location.
If you like the plugin then Help Spread the Word!
At first glance the Google Map API may seem scary, I mean, were do you possibly start? You probably only want to display a simple map that displays directions to your clients address, you don’t really want an all singing and dancing interactive map with more options than necessary. There has to be a simpler way. Of course there is, and as with almost all web site interactivity, jQuery does offer some simple and easy to use plugins. The plugins below offer not only an easier method to install a map, they also offer the option to add extra functionality, should you choose to need them. They also all come with a varied degree of docs, some are extensive and some non-existent, so choose your plugin wisely. I have also listed a couple of beginner jQuery and Google Map tutorials at the the bottom of the post. If you are taking your first steps within Google Maps, I suggest you start there.
Before you install any of these plugins you may want to firstly download the latest version of jQuery, and secondly you had better grab your Google Map API Key here: Sign Up for the Google Maps API.
For one of my recent clients I had to add a google map to the website that allowed people to put in their address and get directions to the festival location.
Looking around I saw a bunch of jQuery plugins that could get the job done. But they were bulky and loaded with features I didn't need.
My solution! Create my own jQuery plugin that allows for simple functionality.
You can create a simple directions application with a From: and To: box that will give users turn by turn directions and highlight the google map with only 1 actual line of javascript (using default ID's and not including the loading of jQuery the plugin or the google API)
You can change where the map is centered when it first loads, Put a custom icon on that location and open a custom tooltip. Perfect for people who want to include directions to their stores, or other places of work.