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