我正在尝试运行以下Geolocation代码,但以下代码返回undefined。请有人指导我吗
当我调用该函数时,例如
警报(verifylocation());
它返回undefined。我想在表单验证中使用它
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#define aSize 2000000
double mean(double* mean_array){
double mean = 0;
for (int i=0; i<aSize; i++){
mean = mean + mean_array[i];
}
mean = mean/aSize;
return mean;
}
double stan_dev_seq(double stan_array[], double stan_mean){
double a = 0;
for (int i=0; i<aSize; i++){
a = a + pow((stan_array[i]-stan_mean), 2);
}
a = a/aSize;
a = sqrt(a);
return a;
}
int pearson_seq(void){
clock_t begin, end;
double time_spent;
begin = clock();
double *a;
a = malloc(sizeof(double)*aSize);
double *b;
b = malloc(sizeof(double)*aSize);
double mean_a;
double mean_b;
for (int i=0; i<aSize; i++){
a[i] = sin(i);
b[i] = sin(i+2);
}
mean_a = mean(a);
mean_b = mean(b);
double stan_dev_a = stan_dev_seq(a, mean_a);
double stan_dev_b = stan_dev_seq(b, mean_b);
double pearson_numer;
for(int i=0; i<aSize; i++){
pearson_numer = pearson_numer + ((a[i]-mean_a)*(b[i]-mean_b));
}
pearson_numer = pearson_numer/aSize;
double pearson_coef = pearson_numer/(stan_dev_a*stan_dev_b);
printf("%s %G\n", "The Pearson Coefficient is: ", pearson_coef);
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("%f %s\n", end, "ms");
printf("%f %s\n", begin, "ms");
printf("%f %s\n", time_spent, "ms");
free(a);
free(b);
return 0;
}
int main(void) {
pearson_seq();
return 0;
}
答案 0 :(得分:0)
您可以使用以下内容:
<!DOCTYPE html>
<html>
<body>
<p>Click the button to get your coordinates.</p>
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
</body>
</html>