我想知道是否有人在同一版本中实施了Google Maps V2和百度地图;因为通用汽车在中国没有按预期运作?
或者我应该将项目拆分为两个分支?但是,跳过两个分支来维护是很好的。
答案 0 :(得分:3)
我的解决方案是像往常一样实施GM,但是如果用户有中国设置(通过设置)静态地图将被使用,但静态地图是从百度而不是谷歌提取的。
staticUrl = "http://api.map.baidu.com/staticimage?center="
+ location.getLongitude() + "," + location.getLatitude()
+ "&width=" + width + "&height=" + width + "&zoom=15"
+ "&markers=" + location.getLongitude() + "," + location.getLatitude();
https://api.map.baidu.com/staticimage?center=121,31&width=300&height=300&zoom=15的结果:
如果尝试实现真实的地图解决方案,则不建议使用此方法。 由于我的不同地点仅供不同国家使用,因此可以使用此解决方案。
所以,这就是我解决它的方式。希望有人觉得这很有帮助。
答案 1 :(得分:2)
另外,我发现如果你在中国使用http://ditu.google.cn,它确实有效。
在中国使用在线地图进行申请时,无论是谷歌地图还是百度,都有transformation of latitude and longitude for legal reasons。
Google地图中的卫星视图使用"地球" (WGS-84)坐标。中国GMaps的地图视图使用" Mars"坐标(GCJ-02),有code to convert between the two。百度地图使用" Bearpaw"坐标,具有不同的偏移量。百度地图API有一个demo converting between Google's coordinates and its own systems。
在中国,GPS就像所有东西一样,有一层额外的复杂功能:)
如果您已构建此应用,请发布详细信息。拥有百度地图的英文界面会很棒。
答案 2 :(得分:1)
您可以同时使用Google地图和百度地图,但请确保从WGS-84坐标(世界上大多数地方使用)转换为百度坐标(BD-09, different from China's GCJ-02)。根据{{3}}:
,这里有一些代码可以执行此操作
// Google coordinates
var gPoint = new BMap.Point(121.4914, 31.2423); // lon, lat of the Bund Museum in Shanghai - https://www.google.com/maps/@31.2423,121.4914,19z
// gPoint = new BMap.Point(-122.0851053, 37.4219593); // lon, lat of the Googleplex (no Baidu map data but zooms out in Mountain View)
var labelOffset = { offset: new BMap.Size(20, -10) };
// Initialize map
var map = new BMap.Map('allmap');
map.centerAndZoom(gPoint, 15);
map.addControl(new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT})); // add scale
map.addControl(new BMap.NavigationControl());
map.addControl(new BMap.MapTypeControl()); // map type control: street/satellite/2.5D
map.enableScrollWheelZoom(); // mouse wheel scroll is disabled by default
// Add Google marker and label
var markerG = new BMap.Marker(gPoint);
map.addOverlay(markerG);
markerG.setLabel(new BMap.Label('Google coordinates marker appears<br/>at incorrect location on Baidu Map', labelOffset));
// Coordinate conversion ... GCJ-02 coordinates ... Baidu coordinates
BMap.Convertor.translate(gPoint, 2, function (point) {
var marker = new BMap.Marker(point);
map.addOverlay(marker);
marker.setLabel(new BMap.Label('Converted to Baidu coordinates:<br/>' +
point.lng + ', ' +
point.lat +
'<br/>(note the offset of ' + (map.getDistance(gPoint, point)).toFixed(2) + ' meters)',
labelOffset));
map.addOverlay(new BMap.Polyline([gPoint, point])); // draw a line between points
});
&#13;
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=gd0GyxGUxSCoAbmdyQBhyhrZ"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
<div id="allmap"></div>
&#13;
如果上面的代码段由于StackOverflow沙箱脚本的方式而无法正常工作,请尝试使用an example from the Baidu Maps API。
如果您必须离线执行转换,请查看GitHub上的JSbin demo of Google -> Baidu coordinates conversion项目。
目前还不清楚用中文本地化的哪种坐标类型的浏览器会通过navigator.geolocation
API返回。我为此制作了一个测试应用程序,并将问题发布在了
evil transform
进一步阅读:
答案 3 :(得分:1)
可能有点迟到了,但我偶然偶然发现了一些可能对你有帮助的事情。
我尝试了百度地图,设置起来非常困难,而且使用起来非常糟糕,所以我环顾四周,突然间,谷歌地图为我工作而没有vpn!
我意识到旧的谷歌中国服务器仍然有效,如果你尝试:
maps.google.cn
您会发现使用google.cn地址创建iframe有效!
答案 4 :(得分:0)
尝试通过Google坐标使用这种方式
http://api.map.baidu.com/marker?location=39.916979519873,116.41004950566&output=html
答案 5 :(得分:-1)
如果您的服务器可以无问题地访问GM(例如,您的托管不在中国大陆,或者它是未经审查的连接),您为什么不让服务器从GM加载数据并将其路由到用户呢?我们过去为少数几个项目做过这样的事情,就像一个魅力。
P.S。你可以从GM获取php拉静态地图以获取请求的长/ lat,将其存储到服务器上的临时文件中,然后将url传递给临时文件。从用户的角度来看,他们会关注(静态)GM。
p.p.s。如果您需要用户能够使用GM的UI(进行平移/缩放),那么您需要更复杂的PHP来改变从GM加载的所有JS,这样所有数据仍然会被请求到您的服务器然后获取地图 - 所以基本上避免客户端机器的任何请求被发送到GM服务器,但所有请求都发送给你的。