开发者

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 ho开发者_高级运维w to go about this/pointers on what I should be reading up on?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜