以下代码允许在单击时获取坐标.但是如何使用Google Maps API在地图上点击地址或城市名称或地区名称或国家/地区?
var myLatlng = new google.maps.LatLng(41.38,2.18);
var myOptions = { zoom: 13, center: myLatlng}
var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
google.maps.event.addListener(map, 'click', function(event) {alert(event.latLng);});Run Code Online (Sandbox Code Playgroud)
html, body, #map-canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}Run Code Online (Sandbox Code Playgroud)
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry,places&ext=.js"></script>
<div id="map-canvas"></div>Run Code Online (Sandbox Code Playgroud)
我的Google地图选项就像
{
center: userLatLng,
zoom: 13,
mapTypeId: 'roadmap',
scrollwheel: false,
navigationControl: false,
mapTypeControl: false,
scaleControl: false,
draggable: true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true,
disableDoubleClickZoom: false,
zoomControl: false,
styles: styles['hide'],
componentRestrictions: {country: "in"},
}
Run Code Online (Sandbox Code Playgroud)
在移动设备上,会显示以下消息:
用两根手指移动地图
如果我用两根手指,我可以移动地图并缩放它.
如何让单个手指可以移动地图,但不能缩放地图?
我想读取来自 Gmail 备份的 3GB .mbox 大文件。这有效:
import mailbox
mbox = mailbox.mbox(r"D:\All mail Including Spam and Trash.mbox")
for i, message in enumerate(mbox):
print("from :",message['from'])
print("subject:",message['subject'])
if message.is_multipart():
content = ''.join(part.get_payload(decode=True) for part in message.get_payload())
else:
content = message.get_payload(decode=True)
print("content:",content)
print("**************************************")
if i == 10:
break
Run Code Online (Sandbox Code Playgroud)
但仅前 10 条消息就需要 40 秒以上。
有没有更快的方法来使用 Python 访问大的 .mbox 文件?
即使以下代码片段看起来很短,我也会在几天内挣扎(对我感到羞耻!)找到一种方法来缩放仅使用CSS3 点击的点transform.它现在有效:
var current = {x: 0, y: 0, zoom: 1}, c = document.getElementById('container');
window.onclick = function(e) {
wx = current.x + e.clientX / current.zoom;
wy = current.y + e.clientY / current.zoom;
var coef = e.ctrlKey ? 0.5 : 2;
current.zoom *= coef;
current.x = wx - e.clientX / current.zoom;
current.y = wy - e.clientY / current.zoom;
c.style.transform = 'scale(' + current.zoom +') translate(' + (-current.x) + 'px,' + (-current.y) + 'px)';
};Run Code Online (Sandbox Code Playgroud)
html, body { …Run Code Online (Sandbox Code Playgroud)我想dict从一个同时运行的多个Python脚本中访问一个唯一的(键/值)数据库.
如果script1.py更新d[2839],script2.py则应在查询几秒后查看修改后的值d[2839].
我想过使用SQLite,但似乎从多个进程并发写入/读取不是SQLite的强项(假设script1.py刚刚修改过d[2839],script2.pySQLite连接怎么会知道它必须重新加载数据库的这个特定部分?)
当我想要刷新修改时,我还考虑过锁定文件(但这样做相当棘手),并使用json.dump序列化,然后尝试检测修改,json.load如果有任何修改则用于重新加载等等......哦,不,我重新发明轮子,重新发明一个特别低效的键/值数据库!
redis看起来像一个解决方案,但它没有正式支持Windows,同样适用于leveldb.
多个脚本可能想要在完全相同的时间写入(即使这是一个非常罕见的事件),有没有办法让数据库系统处理这个(感谢一个锁定参数?似乎默认SQLite不能做这是因为"SQLite支持无限数量的同时读者,但它只会在任何时刻允许一位作者.")
什么是Pythonic解决方案呢?
注意:我在Windows上,并且dict应该有最多1M项(键和值都是整数).
我正在用 Javascript 做一个小数字键盘,但我无法通过.以下方式添加小数点:<input type="number">
document.getElementById('2').onclick = () => document.getElementById('input').value += '2';
document.getElementById('.').onclick = () => document.getElementById('input').value += '.';Run Code Online (Sandbox Code Playgroud)
<input id="input" type="number" value="3"></input>
<div id="2">click to add 2</div>
<div id=".">click to add .</div>Run Code Online (Sandbox Code Playgroud)
指定值“3”。无法解析,或者超出范围。
但另一方面,当输入有焦点时,我们可以用键盘手动输入小数点。
完整示例:
var target = document.querySelector('#input');
document.querySelectorAll('.calcbutton').forEach(el => el.addEventListener("click", evt => { target.value += evt.target.innerHTML; }));
document.querySelector('.calcpoint').onclick = evt => { if (!target.value.includes('.')) target.value += '.'; };Run Code Online (Sandbox Code Playgroud)
<input id="input" type="number"></input>
<div id="calc">
<table>
<tr><td class="calcbutton">7</td><td class="calcbutton">8</td><td class="calcbutton">9</td></tr>
<tr><td class="calcbutton">4</td><td class="calcbutton">5</td><td class="calcbutton">6</td></tr>
<tr><td …Run Code Online (Sandbox Code Playgroud)很容易重新采样数组
a = numpy.array([1,2,3,4,5,6,7,8,9,10])
Run Code Online (Sandbox Code Playgroud)
具有整数重采样因子.例如,使用因子2:
b = a[::2] # [1 3 5 7 9]
Run Code Online (Sandbox Code Playgroud)
但是使用非整数重采样因子,它不会那么容易:
c = a[::1.5] # [1 2 3 4 5 6 7 8 9 10] => not what is needed...
Run Code Online (Sandbox Code Playgroud)
它应该是(使用线性插值):
[1 2.5 4 5.5 7 8.5 10]
Run Code Online (Sandbox Code Playgroud)
或(通过采取阵列中最近的邻居)
[1 3 4 6 7 9 10]
Run Code Online (Sandbox Code Playgroud)
如何使用非整数重采样因子重新采样numpy数组?
应用示例:音频信号重采样/重新排样
使用"我不是机器人"Recpatcha的传统方式似乎是<form>在客户端:
<form action="post.php" method="POST">
<div class="g-recaptcha" data-sitekey="6Lc_0f4SAAAAAF9ZA_d7Dxi9qRbPMMNW-tLSvhe6"></div>
<button type="submit">Sign in</button>
</form>
<script src='https://www.google.com/recaptcha/api.js'></script>
Run Code Online (Sandbox Code Playgroud)
然后一些g-recaptcha-response将被发送到服务器.
但是,在我的代码中,我不使用<form>但是使用AJAX调用:
$('#btn-post').click(function(e) {
$.ajax({
type: "POST",
url: "post.php",
data: {
action: 'post',
text: $("#text").val(),
ajaxMode: "true"
},
success: function(data) { },
error: function(data) { }
}); } });
Run Code Online (Sandbox Code Playgroud)
如何g-recaptcha-response通过此解决方案获得答案?
我正在使用三星A3,Android 5.0.2.我正在使用此设置来编译应用程序,即Android 4.1 Jelly Bean(API 16)目标.
我确切地知道了外部可移动microSD卡的路径/mnt/extSdCard/(参见下面的注释#7).
问题:我注意到了
File myDir = new File("/mnt/extSdCard/test");
myDir.mkdirs();
Run Code Online (Sandbox Code Playgroud)
不起作用:没有创建目录.
也:
File file = new File("/mnt/extSdCard/books/test.txt"); // the folder "books" already exists on the external microSD card, has been created from computer with USB connection
FileOutputStream fos = new FileOutputStream(file);
Run Code Online (Sandbox Code Playgroud)
产生此错误:
java.io.FileNotFoundException:/mnt/extSdCard/books/test.txt:open failed:libcore.io.IoBridge.open中的EACCES(权限被拒绝)(...
如何强制读取+写入外部可移动microSD卡?
笔记:
Environment.getExternalStorageDirectory().toString()给出了/storage/emulated/0我的手机内部存储,即不是我想要的.
getExternalFilesDir(null)给出/storage/emulated/0/Android/data/com.blahblah.appname/files/即不是我想要的东西.请注意,我不能getExternalFilesDirs在决赛中使用,s因为这在API16中不可用.此外,API16中也没有运行时权限.
我已经拥有了<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />,而且READ_EXTERNAL_STORAGE.
我读了很多喜欢的话题这一个或这一个,其实大概20类似的问题,但最后似乎很复杂,一切都和它的相反之说.那是我的我正在寻找特定于这种情况的解决方案.
我不想ACTION_OPEN_DOCUMENT …
假设我们使用 Unix 时间戳列在 Sqlite 数据库中记录事件ts:
CREATE TABLE data(ts INTEGER, text TEXT); -- more columns in reality
Run Code Online (Sandbox Code Playgroud)
并且我们想要快速查找日期时间范围,例如:
SELECT text FROM data WHERE ts BETWEEN 1608710000 and 1608718654;
Run Code Online (Sandbox Code Playgroud)
像这样,EXPLAIN QUERY PLAN给出SCAN TABLE data哪个不好,所以一个明显的解决方案是创建一个带有CREATE INDEX dt_idx ON data(ts).
然后问题就解决了,但是对于一个已经增加的序列/已经排序的列维护一个索引,我们可以直接在 O(log n) 中使用B 树搜索,这是一个相当糟糕的解决方案。在内部,这将是索引:ts
ts rowid
1608000001 1
1608000002 2
1608000012 3
1608000077 4
Run Code Online (Sandbox Code Playgroud)
这浪费了数据库空间(当查询必须首先查看索引时浪费 CPU)。
为避免这种情况:
(1)我们可以使用ts的INTEGER PRIMARY KEY,所以ts会是 …
javascript ×4
python ×3
google-maps ×2
sqlite ×2
ajax ×1
android ×1
arrays ×1
audio ×1
captcha ×1
css ×1
css3 ×1
database ×1
dictionary ×1
email ×1
forms ×1
html-input ×1
java ×1
mbox ×1
numpy ×1
recaptcha ×1
resampling ×1
sql ×1
time-series ×1
transform ×1
transition ×1