A lot of map mashups out there have country-wide or world-wide content. That's awesome because it means there's something for everyone. What's not so awesome is that it means that when I get to the map, I often have to spend some time panning and zooming until I'm in my hometown and seeing the local content I'm most interested in. And as you know from previous posts, I'm inherently lazy and get bored whenever I'm forced to engage in unnecessary mouse movement. Wouldn't it be better if the map could automatically center to my location without me lifting one of my precious fingers? The answer is yes, and now it's easier to do than ever with the introduction of IP-based location information in the AJAX APIs framework.
To add user-based centering to your map mashup, follow the steps below.
<script>
google.load("maps", "2")
Check out the example implementation below, but feel free to make your own implementation snazzier (perhaps by adding a GControl to let the user easily jump to their location):
GControl
For more information, read the docs on using the AJAX Loader and using ClientLocation, or post in the AJAX APIs group with questions. If you're developing a mobile website and want a more precise location for your users, check out the GeoLocation module in Gears.
Give us feedback in our Product Forums.