2013-03-19 3 views
0

Я делаю пользовательскую карту google для игры, все идет очень хорошо, но у меня есть проблемы, добавляющие возможность для людей ссылаться на текущую часть на карте.Как добавить ссылку на текущее местоположение на пользовательской карте Google?

, например: http://www.gta4.net/map/?lat=-19.775390625&lng=-7.91015625&z=5

делает эта функция существует в API или это заказ сценарий? Если да, как я могу это достичь?

ответ

0

Эта функциональность не существует в API, но легко добавить (не проверено):

// If there are any parameters at eh end of the URL, they will be in location.search 
// looking something like "?marker=3" 

// skip the first character, we are not interested in the "?" 
var query = location.search.substring(1); 

// split the rest at each "&" character to give a list of "argname=value" pairs 
var pairs = query.split("&"); 
for (var i=0; i<pairs.length; i++) { 
    // break each pair at the first "=" to obtain the argname and value 
    var pos = pairs[i].indexOf("="); 
    var argname = pairs[i].substring(0,pos).toLowerCase(); 
    var value = pairs[i].substring(pos+1).toLowerCase(); 

    // process each possible argname - use unescape() if theres any chance of spaces 
    if (argname == "id") {id = unescape(value);} 
    if (argname == "marker") {index = parseFloat(value);} 
    if (argname == "lat") {lat = parseFloat(value);} 
    if (argname == "lng") {lng = parseFloat(value);} 
    if (argname == "zoom") {zoom = parseInt(value);} 
    if (argname == "type") { 
    // from the v3 documentation 8/24/2010 
    // HYBRID This map type displays a transparent layer of major streets on satellite images. 
    // ROADMAP This map type displays a normal street map. 
    // SATELLITE This map type displays satellite images. 
    // TERRAIN This map type displays maps with physical features such as terrain and vegetation. 
    if (value == "m") {maptype = google.maps.MapTypeId.ROADMAP;} 
    if (value == "k") {maptype = google.maps.MapTypeId.SATELLITE;} 
    if (value == "h") {maptype = google.maps.MapTypeId.HYBRID;} 
    if (value == "t") {maptype = google.maps.MapTypeId.TERRAIN;} 

    } 
} 

// create the map 
    var myOptions = { 
    zoom: zoom, 
    center: new google.maps.LatLng(lat,lng), 
    mapTypeId: maptype, 
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}, 
    navigationControl: true, 
    mapTypeId: maptype 
} 
map = new google.maps.Map(document.getElementById("map_canvas"), 
           myOptions); 

working example (перенесен из примера на this page of Mike Williams' v2 tutorial)

Смежные вопросы