我正在为一个项目做一些测试,我想到的是涉及到附近的地方.所以我跟那个大家伙一起开始搞乱Google的Places Api.我正在使用带有openstreet瓷砖的传单来制作我的地图.现在一切都很好,直到我尝试使用dang的东西.
var lat = coords.lat;
var lng = coords.lng;
var apiUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json";
var data = {
key: 'AIzaSyBl8bmE8kQT7RjoXhP6k2yDti44h9-fSUI',
location: lat+','+lng,
radius: '10000',
sensor: 'false',
rankby: 'prominence',
types: 'bar|night_club'
};
$.ajax({
url: apiUrl,
type: 'POST',
data: data,
dataType:"jsonp",
crossDomain: true,
success: function(data) {
var obj = $.parseJSON(data);
// console.log(data.next_page_token);
}
});
Run Code Online (Sandbox Code Playgroud)
更改dataType属性json我得到Origin http://localhost is not allowed by Access-Control-Allow-Origin.使用jsonp我得到一个解析错误Unexpected token :Obviusly $.parseJSON不起作用...有没有办法使这项工作,而不必使用谷歌地图Api?如果答案是否定的......是否有其他地方api和google一样好?
谢谢!
我正在尝试dynatable和我遇到一个问题.我不知道如何更新不同的json文件中的记录.
我的HTML身体:
<input type="button" value="items a" id="setToItemsA"><br>
<input type="button" value="items b" id="setToItemsB"><br>
<br><br>
<table id="my-final-table">
<thead>
<th>Band</th>
<th>Song</th>
</thead>
<tbody>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我的剧本
$(document).ready(function() {
var json1 = [
{
"band": "Weezer",
"song": "El Scorcho"
},
{
"band": "Chevelle",
"song": "Family System"
}
];
var json2 = [
{
"band": "Band1",
"song": "Song1"
},
{
"band": "Band2",
"song": "Song2"
}
];
$('#my-final-table').dynatable({
dataset: {
records: json1
}
});
$('#setToItemsA').click(
function() {
setToItems(json1);
});
$('#setToItemsB').click(
function() {
setToItems(json2);
});
function setToItems …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
<?php
header("Expires: Mon, 26 Jul 1990 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
//TESTING CONNECT
include 'connect.php';
$mysqli = connectDB();
getWells(2, $mysqli);
function getWells($company,$mysqli){
//include 'connect.php';
define("MAX_TOP", 96);//96 INCHES == 8 FEET
define("BARRELS_PER_INCH", 1.67);
//$company = $_GET['company'];
//$mysqli = connectDB();
$count = 0;
$sql = "SELECT wells.id, name, top, bottom, last_pulled, bbl_per_hour
FROM wells, history
WHERE company_id ='$company'
AND wells.id = well_id
AND …Run Code Online (Sandbox Code Playgroud) 出于显而易见的原因,我刚刚开始使用依赖注入,并且没有阅读控制反转 (IoC),很快就发现实例化我的一些类时过于冗长的问题。因此,在阅读 IoC 时,我有一个尚未找到具体答案的问题。什么时候应该进行班级注册?在引导程序中?执行前?如何强制执行依赖项的类型?
我没有使用任何框架。为了学习,我编写了自己的容器。
这是我的容器和一些示例类的一个非常低调的示例。
class DepContainer
{
private static $registry = array();
public static function register($name, Closure $resolve)
{
self::$registry[$name] = $resolve;
}
public static function resolve($name)
{
if (self::registered($name)) {
$name = static::$registry[$name];
return $name();
}
throw new Exception('Nothing bro.');
}
public static function registered($name)
{
return array_key_exists($name, self::$registry);
}
}
class Bar
{
private $hello = 'hello world';
public function __construct()
{
# code...
}
public function out()
{
echo $this->hello . "\n";
}
}
class …Run Code Online (Sandbox Code Playgroud) php design-patterns dependency-injection inversion-of-control
我有一个简单的类,它有一些方法(现在)。我可以实例化它并调用 init 函数,但我不能从onchange属性调用另一个方法。
这是课程:
var ScheduleViewer = (function() {
var options = {
container: 'trip_stops',
schedule: {}
};
function ScheduleViewer (){};
ScheduleViewer.prototype.init = function(params) {
$.extend(options, params);
// setTimeout(function() {
// ScheduleViewer.addListener(options);
// }, 3000);
this.addListener(options);
}
ScheduleViewer.prototype.getSchedule = function(trip_id) {
var _id = trip_id;
console.log(_id);
}
ScheduleViewer.prototype.addListener = function(options) {
console.log("adding listener");
var _id = options.select_id;
console.log($('#train_select').length);// zero assuming timing issue
$('#'+_id).on('change', function() {
alert("changed");
})
}
return ScheduleViewer;
})();
Run Code Online (Sandbox Code Playgroud)
电话
<div id="trip_stops" class="trip_options">
<% if (trips.length …Run Code Online (Sandbox Code Playgroud) 我学习如何使用mockery来运行一些单元测试,我不知道如何模拟我的数据库类.它由可以像这两个示例链接的单独方法组成:
$db->select('someTblName',['fieldName'])
->where('fieldName', 'someValue')
->runQuery()
->fetch(); //returns array or null
Run Code Online (Sandbox Code Playgroud)
另一种用途可能是:
$db->select('someTblName')
->where('fieldName', 'someValue')
->where('fieldName', array('>=' , 'someValue')
->runQuery()
->fetch(); //returns array or null
Run Code Online (Sandbox Code Playgroud)
从阅读一些文档,我看到我可以做的事情:(对于第一种情况)
$db = \Mockery::mock('Database');
$db->shouldReceive('select', 'where', 'runQuery', 'fetcth')
->with(??????)
->andReturn(null);
Run Code Online (Sandbox Code Playgroud)
现在我对如何将"对应"参数传递给方法感兴趣?而且,我将如何模拟第二种情况.
我从ppa安装了redis 2.8.12,但无法启动.查看日志这是我得到的:
[4886 | signal handler] (1405388991) Received SIGTERM, scheduling shutdown...
[4886] 14 Jul 20:49:51.561 # User requested shutdown...
[4886] 14 Jul 20:49:51.561 * Saving the final RDB snapshot before exiting.
[4886] 14 Jul 20:49:51.566 * DB saved on disk
[4886] 14 Jul 20:49:51.566 * Removing the pid file.
[4886] 14 Jul 20:49:51.566 # Redis is now ready to exit, bye bye...
[6726] 14 Jul 20:56:04.063 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
[6726] …Run Code Online (Sandbox Code Playgroud) 在使用js中的日期时间时,我不是特别熟练.我有一个JSON对象,有一些日期时间字段格式化,就像YYYY-MM-DDTHH:MM:SS现在我必须把它放进去HH:mm AM/PM,我想出了:
var d = Date.parse('2013-04-17T13:05:00');
var date = new Date(d);
var hrs = date.getUTCHours();
var min = date.getUTCMinutes();
var meridian;
if(hrs > 12){
hrs -= 12;
meridian = 'PM';
}
else {
meridian = 'AM';
}
if (min < 10) {
min = "0"+min;
};
var time = hrs+":"+min+" "+meridian;
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来实现这一目标?
所以我最近开始使用Maps Api v3,当我尝试进行附近搜索时,我得到并且未定义错误.在这条线上var service_places = new google.maps.places.PlacesService(map);
function setupMap (position) {
// console.log(position);
var curLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// console.log(curLocation);
var mapContainer = document.getElementById('map-container');
var mapOptions = {
zoom: 13,
center: curLocation,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
}
};
map = new google.maps.Map(mapContainer,mapOptions);
var marker = new google.maps.Marker ({
position: curLocation,
map: map,
title: "I am here :)"
});
getNearMe(curLocation);
}
function getNearMe (curLocation) {
var request = {
loacation: curLocation,
radius: '10000', …Run Code Online (Sandbox Code Playgroud) 我需要一些帮助来确定为什么apache告诉我我的文档根目录不存在.
我的文档根是/home/user/Documents/Git/site/index.html......它就在那里!
我的vhost看起来像
<VirtualHost *:80>
ServerName site.com
DocumentRoot /home/user/Documents/Git/site/index.html
ErrorLog /home/user/Documents/Git/site/error.log
<Directory /home/user/Documents/Git/site>
Require all granted
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
Git及其子文件夹和文件以及我的主机中的权限为775 127.0.1.1 site.com
我究竟做错了什么?
谢谢
我正在使用Leaflet来标记一系列标记.我正在使用MarkerCluster插件来创建集群.我现在正在做什么我将地图的视图设置为我的数组的第一点.我要做的就是使地图居中,以便用户可以在地图加载时查看所有点/群集.
我的阵列看起来像m = [L.Marker, L.Marker,...].我将每个添加到我的群集组,如:
var markers = L.MarkerClusterGroup();
for(var i = 0; i < m.length; i++){
markers.addLayer(m[i]);
}
Run Code Online (Sandbox Code Playgroud) jquery ×5
javascript ×4
php ×3
apache2 ×1
cors ×1
date ×1
datetime ×1
dynatable ×1
html ×1
html5 ×1
leaflet ×1
mockery ×1
mysql ×1
mysqli ×1
redis ×1
time ×1
ubuntu-13.10 ×1
ubuntu-14.04 ×1
unit-testing ×1