12

是否可以使用谷歌地图 api 来获取时区?我已经在使用它的 api 进行地理编码和地图显示,我也想添加时区。但我在文档中找不到任何东西。

有任何想法吗?链接?

4

2 回答 2

15

您可以使用时区 API

例如(使用 jQuery):

$.ajax({
   url:"https://maps.googleapis.com/maps/api/timezone/json?location=6.123123,106.213144&timestamp="+(Math.round((new Date().getTime())/1000)).toString(),
})
.done(function(response){
   if(response.data.timeZoneId != null){
     //do something
   }
});

您可以从 GoogleMaps API 获取位置坐标(纬度/经度)。

请注意,您需要一个特定的密钥才能使用此 API

于 2013-11-10T06:46:54.303 回答
1

选择时区

var lat=23.8103771
var long=90.41245449999997
$.ajax({
		 url:"https://maps.googleapis.com/maps/api/timezone/json?location=" + lat + "," + long + "&timestamp="+(Math.round((new Date().getTime())/1000)).toString()+"&sensor=false",
			}).done(function(response){
				 if(response.timeZoneId != null){
                   var hour=(response.rawOffset)/60
                   //alert(hour)
					 
                   $('#timezone option[value="'+hour+'"]').prop('selected', true)
                   
				 }
		});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="timezone" id="timezone" style="width:300px;">
                  
          <option value="-720">(GMT - 12:00 hours) Enitwetok, Kwajalien</option>
                  
          <option value="-660">(GMT - 11:00 hours) Midway Island, Samoa</option>
                  
          <option value="-600">(GMT - 10:00 hours) Hawaii</option>
                  
          <option value="-540">(GMT - 9:00 hours) Alaska</option>
                  
          <option value="-480">(GMT - 8:00 hours) Pacific Time (US &amp; Canada)</option>
                  
          <option value="-420">(GMT - 7:00 hours) Mountain Time (US &amp; Canada)</option>
                  
          <option value="-360">(GMT - 6:00 hours) Central Time (US &amp; Canada), Mexico City</option>
                  
          <option value="-300">(GMT - 5:00 hours) Eastern Time (US &amp; Canada), Bogota, Lima, Quito</option>
                  
          <option value="-240">(GMT - 4:00 hours) Atlantic Time (Canada), Caracas, La Paz</option>
                  
          <option value="-210">(GMT - 3:30 hours) Newfoundland</option>
                  
          <option value="-180">(GMT - 3:00 hours) Brazil, Buenos Aires, Georgetown, Falkland Isl.</option>
                  
          <option value="-120">(GMT - 2:00 hours) Mid-Atlantic, Ascention Isl., St Helena</option>
                  
          <option value="-60">(GMT - 1:00 hour) Azores, Cape Verde Islands</option>
                  
          <option value="0">(GMT) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia</option>
                  
          <option value="60">(GMT + 1:00 hour) Amsterdam, Berlin, Copenhagen, Madrid, Paris, Rome</option>
                  
          <option value="120">(GMT + 2:00 hours) Kaliningrad, South Africa, Warsaw</option>
                  
          <option value="180">(GMT + 3:00 hours) Baghdad, Riyadh, Moscow, Nairobi</option>
                  
          <option value="210">(GMT + 3:30 hours) Tehran</option>
                  
          <option value="240">(GMT + 4:00 hours) Adu Dhabi, Baku, Muscat, Tbilisi</option>
                  
          <option value="270">(GMT + 4:30 hours) Kabul</option>
                  
          <option value="300">(GMT + 5:00 hours) Ekaterinburg, Islamabad, Karachi, Tashkent</option>
                  
          <option value="330">(GMT + 5:30 hours) Bombay, Calcutta, Madras, New Delhi</option>
                  
          <option value="360">(GMT + 6:00 hours) Almaty, Colomba, Dhaka</option>
                  
          <option value="420">(GMT + 7:00 hours) Bangkok, Hanoi, Jakarta</option>
                  
          <option value="480">(GMT + 8:00 hours) Beijing, Hong Kong, Perth, Singapore, Taipei</option>
                  
          <option value="540">(GMT + 9:00 hours) Osaka, Sapporo, Seoul, Tokyo, Yakutsk</option>
                  
          <option value="570">(GMT + 9:30 hours) Adelaide, Darwin</option>
                  
          <option value="600">(GMT + 10:00 hours) Melbourne, Papua New Guinea, Sydney, Vladivostok</option>
                  
          <option value="660">(GMT + 11:00 hours) Magadan, New Caledonia, Solomon Islands</option>
                  
          <option value="720">(GMT + 12:00 hours) Auckland, Wellington, Fiji, Marshall Island</option>
          
        </select>

于 2015-12-27T19:25:34.347 回答