Difficulty Adding Transit Layer to Google Maps - google-maps

I am trying to add the Transit Layer to an existing map that came with my wordpress theme. I'm not sure if I'm doing it wrong but the map stops loading whenever I add the code that I found here (https://developers.google.com/maps/documentation/javascript/trafficlayer#transit_layer)
I know the file I need to edit is located in js/google_js/google_map_js and it looks like this......
/*global google */
/*global Modernizr */
/*global InfoBox */
/*global googlecode_regular_vars*/
var gmarkers = [];
var current_place=0;
var actions=[];
var categories=[];
var vertical_pan=-190;
var map_open=0;
var vertical_off=150;
var pins='';
var markers='';
var infoBox = null;
var category=null;
var width_browser=null;
var infobox_width=null;
var wraper_height=null;
var info_image=null;
var map;
var found_id;
var selected_id = '';
var javamap;
var oms;
function initialize(){
"use strict";
var mapOptions = {
flat:false,
noClear:false,
zoom: parseInt(googlecode_regular_vars.page_custom_zoom),
scrollwheel: false,
draggable: true,
center: new google.maps.LatLng(googlecode_regular_vars.general_latitude, googlecode_regular_vars.general_longitude),
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl:false,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP]
},
disableDefaultUI: true
};
if( document.getElementById('googleMap') ){
map = new google.maps.Map(document.getElementById('googleMap'), mapOptions);
}else{
return;
}
google.maps.visualRefresh = true;
if(mapfunctions_vars.show_g_search_status==='yes'){
set_google_search(map)
}
if(mapfunctions_vars.map_style !==''){
var styles = JSON.parse ( mapfunctions_vars.map_style );
map.setOptions({styles: styles});
}
google.maps.event.addListener(map, 'tilesloaded', function() {
jQuery('#gmap-loading').remove();
});
if (Modernizr.mq('only all and (max-width: 1025px)')) {
map.setOptions({'draggable': false});
}
if(googlecode_regular_vars.generated_pins==='0'){
pins=googlecode_regular_vars.markers;
markers = jQuery.parseJSON(pins);
}else{
if( typeof( googlecode_regular_vars2) !== 'undefined' && googlecode_regular_vars2.markers2.length > 2){
pins=googlecode_regular_vars2.markers2;
markers = jQuery.parseJSON(pins);
}
}
if (markers.length>0){
setMarkers(map, markers);
}
if(googlecode_regular_vars.idx_status==='1'){
placeidx(map,markers);
}
//set map cluster
map_cluster();
/*function scrollwhel(event){
if(map.scrollwheel===true){
event.stopPropagation();
}
}
google.maps.event.addDomListener(document.getElementById('googleMap'), 'mousewheel', scrollwhel);
google.maps.event.addDomListener(document.getElementById('googleMap'), 'DOMMouseScroll', scrollwhel);
*/
oms = new OverlappingMarkerSpiderfier(map, {markersWontMove: true, markersWontHide: true,keepSpiderfied :true,legWeight:3});
setOms(gmarkers);
}
///////////////////////////////// end initialize
///////////////////////////////////////////////////////////////////////////////////
if (typeof google === 'object' && typeof google.maps === 'object') {
google.maps.event.addDomListener(window, 'load', initialize);
}
I know that the code that I need to enter is this....
function initialize() {
var myLatlng = new google.maps.LatLng(51.501904,-0.115871);
var mapOptions = {
zoom: 13,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var transitLayer = new google.maps.TransitLayer();
transitLayer.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
Any help at all would be greatly appreciated. Thank you.

I think you should add the TransitLayer code:
var transitLayer = new google.maps.TransitLayer();
transitLayer.setMap(map);
under the map object generation code:
map = new google.maps.Map(document.getElementById('googleMap'), mapOptions);
var transitLayer = new google.maps.TransitLayer();
transitLayer.setMap(map);
Then it should work.
working fiddle

Related

Google maps displaying other side of the planet

I have literally been trying anything and everything, but the map displays somewhere in Antarctica, when the coordinates that I am receiving, are for cities in the US.
The following is the code that inits the map:
$(window).on('load', function() {
// eslint-disable-next-line
function initTest() {
var fastestCitiesApi = JSON.parse(document.getElementById('fastestCitiesApi').value);
console.log(fastestCitiesApi);
var tempLatLng = fastestCitiesApi[0]['latLng'];
console.log(tempLatLng);
var latLng = tempLatLng.split(',');
console.log('latLng[0]: ' + latLng[0]);
console.log('latLng[1]: ' + latLng[1]);
const myLatLng = new google.maps.LatLng({ lat: parseFloat(latLng[0]), lng: parseFloat(latLng[1]) });
const mapOptions = {
zoom: 4,
center: myLatLng
};
const map = new google.maps.Map(document.getElementById('fastest_cities_map'), mapOptions);
new google.maps.Marker({
position: myLatLng,
map,
title: 'somewhere',
});
}
initTest();
});
As you can see by the following screen shot of the console is showing, that the coordinates are 36, 78 - which when I do a look up on google for Boydton, VA - those are the coordinates that is returned - link to google search for Boydton, VA lat long
As you can see by the screen shot, I have zero errors. What am I doing wrong?
Thanks in advance
Thanks to #Gray pointing out that the long should be negative, the rest of the array loaded up the markers as expected.
Here's the final code:
$(window).on('load', function() {
// eslint-disable-next-line
function initTest() {
/* init vars */
const map = new google.maps.Map(document.getElementById('fastest_cities_map'));
var fastestCitiesApi = JSON.parse(document.getElementById('fastestCitiesApi').value);
// console.log(fastestCitiesApi);
var tempLatLng = '';
var latLng = [];
var markerOptionsArray = new Array();
var latlngArray = new Array();
var myLat = new Array();
var myLng = new Array();
var markers = [];
var nameArray = [];
var infowindow = new google.maps.InfoWindow({maxWidth: 350});
/* create arrays for markers */
for(var item in fastestCitiesApi) {
tempLatLng = fastestCitiesApi[item]['latLng'];
nameArray.push(fastestCitiesApi[item]['city']);
// console.log(tempLatLng);
latLng = tempLatLng.split(',');
myLat.push(latLng[0]);
myLng.push(latLng[1]);
// console.log('latLng[0]: ' + latLng[0]);
// console.log('latLng[1]: ' + latLng[1]);
markers.push({
lat: myLat[item],
lng: myLng[item],
name: nameArray[item],
});
}
// console.log('markers: ' + JSON.stringify(markers));
var bounds = new google.maps.LatLngBounds();
for (var v=0; v<markers.length; v++)
{
var secheltLoc = new google.maps.LatLng(markers[v].lat, markers[v].lng);
var myOptions = {
content: markers[v].name
,boxStyle: {
border: "none"
,textAlign: "center"
,fontSize: "12pt"
,width: "120px"
}
,disableAutoPan: true
,pixelOffset: new google.maps.Size(-50, 0)
,position: secheltLoc
,closeBoxURL: ""
,isHidden: false
,pane: "mapPane"
,enableEventPropagation: true
};
var marker = new google.maps.Marker({
position: new google.maps.LatLng(markers[v].lat, markers[v].lng),
map: map,
center: new google.maps.LatLng(markers[v].lat, markers[v].lng)
});
google.maps.event.addListener(marker, 'click', (function (marker, v) {
return function () {
infowindow.setContent(markers[v].name);
infowindow.open(map, marker);
}
})(marker, v));
google.maps.event.addListener(map, 'click', function () {
infowindow.close();
marker.open = false;
});
bounds.extend(new google.maps.LatLng(markers[v].lat, markers[v].lng));
myLatLng = markers[v].lat+','+markers[v].lng;
}
map.fitBounds(bounds);
}
// alert(google.maps.Map);
initTest();
});
The following is a screen shot of the result of the eight city array:

Can I use the google maps javascript api to display both points and polylines?

I am in the middle of a coding an asset map for one of my customers assets.
The database contain information as below in two tables
tblAssets
AssetID
AssetName
AssetLocation
AssetLat
AssetLng
AssetType
tblAssetLinks
LinkID
LinkType
LinkLat1
LinkLng1
LinkLat2
LinkLng2
tblAssets is used to plot the individual assets, these contain other information (irrelevant to this issue) and tblAssetLinks in their current application draws a line between LinkLat1, LinkLng1 and LinkLat2, LinkLng2
I have managed to get tblAssets to plot loading the db as an xml array as below
<markers>
<marker PrimaryKey="175223" NodeName="TQ88768407" distance="0.0123043158297526" lat="51.455662" lng="0.716716" Type="NODE"/>
<marker PrimaryKey="175221" NodeName="TQ88768405" distance="0.0175958000932205" lat="51.455498" lng="0.716893" Type="NODE"/>
<marker PrimaryKey="175226" NodeName="TQ88768411" distance="0.023174171700034" lat="51.455791" lng="0.716119" Type="NODE"/>
</markers>
This is the javascript i am using to load my points onto my map
<script type="text/javascript">
//<![CDATA[
var customIcons = {
OTHER: {
icon: 'images/other.png'
}
};
function load() {
//map.addMapType(G_SATELLITE_3D_MAP);
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(51.4555503, 0.7164931),
zoom: 18,
mapTypeId: 'hybrid'
});
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("xmlgen_asset.php?lat=51.4555503&lng=0.7164931", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var primarykey = markers[i].getAttribute("PrimaryKey");
var nodename = markers[i].getAttribute("NodeName");
var ownedby = markers[i].getAttribute("OwnedBy");
var nodeid = markers[i].getAttribute("NodeID");
var type = markers[i].getAttribute("Type");
var lat = markers[i].getAttribute("lat");
var lng = markers[i].getAttribute("lng");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = nodename + "<br/>" + type;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
//]]>
</script>
I was wondering if there was a way for me to load another xml with tblAssetLinks to draw polylines as well as the points above onto the map?
To parse that XML, get each link element, retrieve their lat1/lng1 and lat2/lng2 attributes and make polylines from them (per the example in the documentation.
var polydata = xml.getElementsByTagName('link');
for (var i = 0; i < polydata.length; i++) {
var pt1 = {
lat: parseFloat(polydata[i].getAttribute("lat1")),
lng: parseFloat(polydata[i].getAttribute("lng1"))
}
var pt2 = {
lat: parseFloat(polydata[i].getAttribute("lat2")),
lng: parseFloat(polydata[i].getAttribute("lng2"))
}
var polyline = new google.maps.Polyline({
path: [pt1, pt2],
map: map
});
}
proof of concept fiddle
code snippet:
var geocoder;
var map;
function initialize() {
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(51, 0),
zoom: 3,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var bounds = new google.maps.LatLngBounds();
var xml = xmlParse(xmlData);
var polydata = xml.getElementsByTagName('link');
for (var i = 0; i < polydata.length; i++) {
var pt1 = {
lat: parseFloat(polydata[i].getAttribute("lat1")),
lng: parseFloat(polydata[i].getAttribute("lng1"))
}
var pt2 = {
lat: parseFloat(polydata[i].getAttribute("lat2")),
lng: parseFloat(polydata[i].getAttribute("lng2"))
}
var polyline = new google.maps.Polyline({
path: [pt1, pt2],
map: map
});
bounds.extend(polyline.getPath().getAt(0));
bounds.extend(polyline.getPath().getAt(1));
}
map.fitBounds(bounds);
}
function xmlParse(str) {
if (typeof ActiveXObject != 'undefined' && typeof GetObject != 'undefined') {
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.loadXML(str);
return doc;
}
if (typeof DOMParser != 'undefined') {
return (new DOMParser()).parseFromString(str, 'text/xml');
}
return createElement('div', null);
}
google.maps.event.addDomListener(window, "load", initialize);
var xmlData = '<links><link PrimaryKey="56669" OwnedBy="SWS" AssetID="30757610" distance="0.0161501151649766" lat1="51.455479" lng1="0.716877" lat2="51.455498" lng2="0.716893" Type="COMBINED"/><link PrimaryKey="45827" OwnedBy="SWS" AssetID="1386010" distance="0.024165762230059" lat1="51.455791" lng1="0.716119" lat2="51.455769" lng2="0.716060" Type="COMBINED"/><link PrimaryKey="92131" OwnedBy="SWS" AssetID="30757581" distance="0.0258313521247188" lat1="51.455750" lng1="0.716015" lat2="51.455734" lng2="0.716000" Type="COMBINED"/><link PrimaryKey="55871" OwnedBy="SWS" AssetID="30757590" distance="0.033043902136047" lat1="51.455833" lng1="0.715905" lat2="51.455853" lng2="0.715906" Type="SURFACE_WATER"/><link PrimaryKey="79135" OwnedBy="SWS" AssetID="1386511" distance="0.0387150798069927" lat1="51.455372" lng1="0.715662" lat2="51.455509" lng2="0.715598" Type="COMBINED"/><link PrimaryKey="55870" OwnedBy="SWS" AssetID="30757560" distance="0.039789930528151" lat1="51.455353" lng1="0.715646" lat2="51.455372" lng2="0.715662" Type="COMBINED"/><link PrimaryKey="79136" OwnedBy="SWS" AssetID="1386531" distance="0.0415342089389798" lat1="51.455051" lng1="0.717068" lat2="51.454903" lng2="0.716886" Type="COMBINED"/><link PrimaryKey="79062" OwnedBy="SWS" AssetID="1386001" distance="0.0424351462005461" lat1="51.455944" lng1="0.715768" lat2="51.455917" lng2="0.715723" Type="SURFACE_WATER"/><link PrimaryKey="2812" OwnedBy="SWS" AssetID="1385989" distance="0.042520172377456" lat1="51.455795" lng1="0.715615" lat2="51.455692" lng2="0.715767" Type="COMBINED"/><link PrimaryKey="4041" OwnedBy="SWS" AssetID="1386420" distance="0.043199028781749" lat1="51.456078" lng1="0.717043" lat2="51.455662" lng2="0.716716" Type="COMBINED"/></links>';
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>

google maps onclick go to marker on map

I'm having issues trying to get my map to go to the marker of a location when a "View on Map" link is clicked. I keep getting the error "TypeError: map.setOptions is not a function".
Here's the code:
var infowindow = null;
function initialize(){
var myOptions = {
zoom:3,
center:new google.maps.LatLng(0,0),
mapTypeId:google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(
document.getElementById('map'),myOptions);
setMarkers(map,sites);
}
var infowindow = new google.maps.InfoWindow({
content:'Loading...'
});
var sites = [
['GIC Campers Sydney',-33.935477,151.012108,1,'xxx'],
['GIC Campers Brisbane',-27.5445735,153.0139405,1,'yyy'],
['GIC Campers Melbourne',-37.650735,144.940551,1,'zzz']
];
function setMarkers(map,markers){
var bounds = new google.maps.LatLngBounds();
var image = new google.maps.MarkerImage('/templates/home/images/google-pin.png',
new google.maps.Size(60,60),
new google.maps.Point(0,0),
new google.maps.Point(30,60));
for(var i=0;i<markers.length;i++){
var sites = markers[i];
var siteLatLng = new google.maps.LatLng(sites[1],sites[2]);
var marker = new google.maps.Marker({
position:siteLatLng,
map:map,
icon:image,
title:sites[0],
zIndex:sites[3],
html:sites[4]
});
google.maps.event.addListener(marker,'click',function(){
map.setZoom(15);
map.setCenter(marker.getPosition());
infowindow.setContent(this.html);
infowindow.open(map,this);
});
bounds.extend(siteLatLng);
map.fitBounds(bounds);
}
};
function loadcity(which){
initialize();
if(which == 'gic-campers-sydney'){
var newPos = new google.maps.LatLng(-33.935477,151.012108);
map.setOptions({center:newPos,zoom:15});
}
if(which == 'gic-campers-brisbane'){
var newPos = new google.maps.LatLng(-27.5445735,153.0139405);
map.setOptions({center:newPos,zoom:15});
}
if(which == 'gic-campers-melbourne'){
var newPos = new google.maps.LatLng(-37.650735,144.940551);
map.setOptions({center:newPos,zoom:15});
}
}
jQuery(document).ready(function(e) {
initialize();
jQuery('.updatemap').click(function(e){
e.preventDefault();
});
});
and an example link:
<a onclick="loadcity('gic-campers-brisbane');" class="updatemap" href="#gic-campers-brisbane">View on map</a>
Any help on this would be greatly appreciated.
Your map variable is local to the initialize function. It is not available inside the loadcity function.
One fix is to make it global (like your infowindow):
var infowindow = null;
var map = null;
function initialize(){
var myOptions = {
zoom:3,
center:new google.maps.LatLng(0,0),
mapTypeId:google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(
document.getElementById('map'),myOptions);
setMarkers(map,sites);
}
Not sure why you recreate the map (call initialize() every time loadcity runs), you really should only need to do that once.

Can someone tell me why I can see an InfoWindow when I click on an map marker?

Here is my code that will pull data from mysql and display the markers on the map. But I cant get the info windows to show when I click on a marker. Thank for any help.
The reference to the infowindows is at the very bottom on the page close to the end of the code after the ajax reference.
Thanks
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
function LoadMarkers(encodedString)
{
var bounds = new google.maps.LatLngBounds();
var stringArray = [];
stringArray = encodedString.split("****");
var x;
for (x = 0; x < stringArray.length; x = x + 1)
{
var addressDetails = [];
var marker;
addressDetails = stringArray[x].split("&&&");
var lat = new google.maps.LatLng(addressDetails[1], addressDetails[2]);
var image = new google.maps.MarkerImage(addressDetails[3]);
var marker = new google.maps.Marker({
map: map,
icon: image,
position: lat,
content: addressDetails[0]
});
markersArray.push(marker);
google.maps.event.addListener( marker, 'click', function () {
closeInfos();
var info = new google.maps.InfoWindow({content: this.content});
info.open(map,this);
infos[0]=info;
});
bounds.extend(lat);
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(map);
}
}
}
map.fitBounds(bounds);
}
var geocoder;
var map;
var markersArray = [];
var infos = [];
geocoder = new google.maps.Geocoder();
var myOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = null;//new google.maps.Map(document.getElementById("map_canvas"), myOptions);
jQuery(document).ready( function($){
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
LoadMarkers(document.getElementById("encodedString").value);
setInterval(function () {
jQuery.ajax({
url:'ajaxload.php',
type: "POST",
data: {'refreshed':true},
success: function(data)
{
LoadMarkers(data);
}
});
}, 10000);
//Manages the info windows
function closeInfos(){
if(infos.length > 0){
infos[0].set("marker",null);
infos[0].close();
infos.length = 0;
}
}
});
The function LoadMarkers is defined in global scope, but the function closeInfos is defined locally inside the $.ready-callback.
Because of that the call of closeInfos() inside the click-handler of the marker fails and stops the further execution of the click-handler.
You must make closeInfos global accessible:
window.closeInfos=function(){
if(infos.length > 0){
infos[0].set("marker",null);
infos[0].close();
infos.length = 0;
}
}

How to get the Google Map based on Latitude on Longitude?

I want to display Google map in my web page based on longitude and latitude. First user want to enter longitude and latitude in two text box's. Then click submit button I have to display appropriate location in Google map.And also I want to show the weather report on it.How to do that? Thank You.
Create a URI like this one:
https://maps.google.com/?q=[lat],[long]
For example:
https://maps.google.com/?q=-37.866963,144.980615
or, if you are using the javascript API
map.setCenter(new GLatLng(0,0))
This, and other helpful info comes from here:
https://developers.google.com/maps/documentation/javascript/reference/?csw=1#Map
this is the javascript to display google map by passing your longitude and latitude.
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
function loadScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;
</script>
Have you gone through google's geocoding api. The following link shall help you get started:
http://code.google.com/apis/maps/documentation/geocoding/#GeocodingRequests
Firstly add a div with id.
<div id="my_map_add" style="width:100%;height:300px;"></div>
<script type="text/javascript">
function my_map_add() {
var myMapCenter = new google.maps.LatLng(28.5383866, 77.34916609);
var myMapProp = {center:myMapCenter, zoom:12, scrollwheel:false, draggable:false, mapTypeId:google.maps.MapTypeId.ROADMAP};
var map = new google.maps.Map(document.getElementById("my_map_add"),myMapProp);
var marker = new google.maps.Marker({position:myMapCenter});
marker.setMap(map);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=your_key&callback=my_map_add"></script>
<script>
function initMap() {
//echo hiii;
var map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(8.5241, 76.9366),
zoom: 12
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP or XML file
downloadUrl('https://storage.googleapis.com/mapsdevsite/json/mapmarkers2.xml', function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('package');
Array.prototype.forEach.call(markers, function(markerElem) {
var id = markerElem.getAttribute('id');
// var name = markerElem.getAttribute('name');
// var address = markerElem.getAttribute('address');
// var type = markerElem.getAttribute('type');
// var latitude = results[0].geometry.location.lat();
// var longitude = results[0].geometry.location.lng();
var point = new google.maps.LatLng(
parseFloat(markerElem.getAttribute('latitude')),
parseFloat(markerElem.getAttribute('longitude'))
);
var infowincontent = document.createElement('div');
var strong = document.createElement('strong');
strong.textContent = name
infowincontent.appendChild(strong);
infowincontent.appendChild(document.createElement('br'));
var text = document.createElement('text');
text.textContent = address
infowincontent.appendChild(text);
var icon = customLabel[type] || {};
var package = new google.maps.Marker({
map: map,
position: point,
label: icon.label
});
package.addListener('click', function() {
infoWindow.setContent(infowincontent);
infoWindow.open(map, package);
});
});
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}