Clorith
Clorith

Reputation: 459

Custom Google Maps location hotlink

I have a custom map using the Google Maps API to navigate it, and I was looking into getting an address for hot-linking to the current location on the map (like the Maps link such as the following; http://maps.google.com/?ie=UTF8&ll=37.0625,-95.677068&spn=64.880423,135.263672&t=h&z=4 )

I'm not quite sure what the feature is called or how to go about this as I've yet to find anything relevant in the API documentation, does anyone know if this is doable with custom maps, and alternatively how to go about this/pointers on what I should be reading up on?

Upvotes: 0

Views: 791

Answers (2)

tiago
tiago

Reputation: 1337

They're called deeplinks, and here's how they work: https://developers.google.com/maps/documentation/urls/get-started

To launch Google Maps and optionally perform one of the supported functions, use a URL scheme of one of the following forms, depending on the action requested:

Upvotes: 0

fredrik
fredrik

Reputation: 17617

I've never seen it in the documentation and don't think it's possible. Been looking for it my self without luck.

You probably need to look on the url's query params and navigate to it with javascript.

Do this onload (let's presume that the var map is you google maps object):

var queryArray = window.location.search.substring(1).split('&'),
    query = {},
    parseQueryByKey = (function () {
        var subQuery = '',
            i = 0;
        for (i = 0; i < queryArray.length; i += 1) {
            if (queryArray[i] && queryArray[i].indexOf('=') !== -1) {
                subQuery = queryArray[i].split('=');
                query[subQuery[0]] = subQuery[1];
            }
        }
    }());
// presumed url http://localhost/?lat=58.1323&lng=18.1231
if (window.location.search && 'lat' in query && 'lng' in query) {
    map.setCenter(new google.maps.LatLng(parseFloat(query['lat']), parseFloat(query['lng'])))
}

Hope it helps.

..fredrik

Upvotes: 1

Related Questions