但在网络服务器上不起作用

但在网络服务器上不起作用

本文介绍了谷歌地图 api 在本地主机上工作,但在网络服务器上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用谷歌地图 api 在地图上选择一些点并找到最短的行车路线.

I used google maps api for selecting some points on map and find to shortest driving route.

一切都在本地主机上工作,但是当我发布并上传到服务器时,它不起作用......

Everythings works in localhost, but when i publish and upload it server, it doesn't work...

为什么会这样?没有任何错误.地图即将出现在页面上,但我看不到标记,并且 directionResult 无法加载结果.是关于授权吗?我有有效的帐户和 api 密钥等.我允许引用我的域.

Why it's happen? There isn't any error. Map is coming on page but i can't see markers and directionResult doesn't load the result. Is it about authorization? I have valid account and api key etc. And i allowed referer of my domain.

我用 crome JS 调试器检查脚本.这里没有反应;

I check the script with crome JS debugger. There is no response here;

directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK)
{
    directionsDisplay.setDirections(response);    }
});

状态在实时服务器上返回"值,而不是OK".在本地主机它的工作!有人知道是什么原因吗?

status returning "" value at live server, not "OK". In localhost its working! Anybody knows whats the reason?

你可以在这里看到google.maps.api的例子;查看源:https://google-developers.appspot.com/maps/documentation/javascript/examples/directions-simple

You can see the example of google.maps.api here; view-source:https://google-developers.appspot.com/maps/documentation/javascript/examples/directions-simple

感谢您的帮助.

推荐答案

我解决了这个问题.它是关于网络服务器的十进制符号.在我的本地主机中,我使用."作为十进制符号.但是在网络服务器中它是,"所以在谷歌地图中,​​纬度和经度点有错误的值,地图api找不到这些点.

I solved the problem. Its about decimal symbol of web server. In my localhost i'm using "." as decimal symbol. But in web server it was "," so in google maps, lat and lang points have wrong values and maps api couldnt find the points.

从区域和语言设置(适用于所有用户)更改网络服务器十进制符号后.它开始工作......

After changing web servers decimal symbol from Regional And Language Settings(for all users). Its start to work...

这篇关于谷歌地图 api 在本地主机上工作,但在网络服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:24