0

我正在为游戏制作自定义谷歌地图,一切进展顺利,但我在为人们添加一个选项以链接到地图上的当前部分时遇到了困难。

例如:http ://www.gta4.net/map/?lat=-19.775390625&lng=-7.91015625&z=5

这个函数是否存在于 api 中或者这是一个定制的脚本?如果是这样,我怎么能做到这一点?

4

1 回答 1

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);

工作示例(从Mike Williams 的 v2 教程页面上的示例移植)

于 2013-03-19T17:00:26.793 回答