OLD | NEW |
| (Empty) |
1 <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAATfHumD
bW3OmRByfquHd3SRTRERdeAiwZ9EeJWta3L_JZVS0bOBRQeZgr4K0xyVKzUdnnuFl8X9PX0w&sensor=
false" | |
2 type="text/javascript"></script> | |
3 <script> | |
4 var maps_key = "ABQIAAAATfHumDbW3OmRByfquHd3SRTRERdeAiwZ9EeJWta3L_JZVS0bOBRQeZgr
4K0xyVKzUdnnuFl8X9PX0w"; | |
5 | |
6 function xhr_geocode(address) { | |
7 var xhr = new XMLHttpRequest(); | |
8 xhr.onreadystatechange = function() { | |
9 if (xhr.readyState == 4 && xhr.status == 200) { | |
10 console.log(xhr.responseText); | |
11 var parsed = JSON.parse(xhr.responseText); | |
12 console.dir(parsed); | |
13 var point = parsed.Placemark[0].Point.coordinates; | |
14 var latlng = point[1] + "," + point[0]; | |
15 window.open("http://maps.google.com/staticmap?center=" + latlng + | |
16 "&markers=" + latlng + "&zoom=14" + | |
17 "&size=512x512&sensor=false&key=" + maps_key, | |
18 "mappy_popup", | |
19 "width=512,height=512"); | |
20 } else { | |
21 console.log("xhr: " + xhr.readyState); | |
22 } | |
23 }; | |
24 var url = | |
25 "http://maps.google.com/maps/geo?output=json&oe=utf8&sensor=false&key=" + | |
26 maps_key + "&q=" + address; | |
27 console.log(url); | |
28 xhr.open("GET", url); | |
29 xhr.send(null); | |
30 } | |
31 | |
32 function gclient_geocode(address) { | |
33 var geocoder = new GClientGeocoder(); | |
34 geocoder.getLatLng(address, function(point) { | |
35 if (!point) { | |
36 console.log(address + " not found"); | |
37 } else { | |
38 var latlng = point.toUrlValue(); | |
39 var url = "http://maps.google.com/staticmap?center=" + latlng + | |
40 "&markers=" + latlng + "&zoom=14" + | |
41 "&size=512x512&sensor=false&key=" + maps_key; | |
42 //window.open(url, "mappy_popup", "width=512,height=512"); | |
43 document.body.style.width = "512px"; | |
44 setTimeout(chrome.toolstrip.expand, 100, 512, url); | |
45 } | |
46 }); | |
47 } | |
48 | |
49 function map() { | |
50 chrome.tabs.getSelected(null, function(tab) { | |
51 var port = chrome.tabs.connect(tab.id); | |
52 if (!port) { | |
53 console.log("no port"); | |
54 } else { | |
55 port.onMessage.addListener(function(data) { | |
56 var address = data.values[0]; | |
57 //xhr_geocode(address); | |
58 gclient_geocode(address); | |
59 }); | |
60 port.postMessage({message: "hello tab: " + tab.id}); | |
61 console.log("sent message"); | |
62 } | |
63 }); | |
64 }; | |
65 </script> | |
66 <div class="toolstrip-button" onclick="map()"> | |
67 <span>Mappy</span> | |
68 </div> | |
OLD | NEW |