简体   繁体   English

利用iOS的本机指南针设备方向的Google Maps API

[英]Google Maps API Utilizing iOS's Native Compass Device Orientation

If you open up Maps on the iPad and click the location arrow twice. 如果您在iPad上打开“地图”,然后单击两次位置箭头。 You will notice that the map will rotate depending on the device's orientation. 您会注意到地图会根据设备的方向旋转。 This is what I want my application's map to do in my iOS Native Web Application. 这就是我希望应用程序的地图在iOS本机Web应用程序中执行的操作。 It's a Google Maps mashup using iOS's Native Compass to point in the direction that I turn. 这是一个使用iOS的本地罗盘指向我转向的Google Maps混搭。 I'm needing this to be done specifically with Javascript. 我需要使用Java专门完成此操作。 If anyone can point me in the right direction I would really appreciate it. 如果有人能指出正确的方向,我将非常感激。

Though this is technically possible by injecting javascript into a UIWebView , rotation of the map itself can be tricky. 尽管从技术上讲可以通过将JavaScript注入UIWebView ,但地图本身的旋转可能比较棘手。

I used to have a web app that I wrapped inside a UIWebView for a native iOS version. 我曾经有一个Web应用程序,该应用程序包装在UIWebView用于本机iOS版本。 The only difference in the iOS version was that I tapped into the CLLocationManager to get heading from the iOS device, and then injected some javascript on each heading update which the webpage responded to be substituting one of 36 arrow icons (one for every 10 degrees) showing the user's current direction. iOS版本中的唯一区别是我点击了CLLocationManager以从iOS设备获取标题,然后在每个标题更新中注入了一些JavaScript,网页对此进行了响应,以替换36个箭头图标之一(每10度一个)显示用户的当前方向。 Check out stringByEvaluatingJavascriptFromString on UIWebView . UIWebView stringByEvaluatingJavascriptFromString

When I did it, I only modified the user's current location icon though, rather than rotating the entire map. 完成此操作后,我只是修改了用户的当前位置图标,而不是旋转整个地图。 I do remember experimenting with rotation the entire map, but had issues where as soon as you rotate the map rectangle, you end up with white triangular areas on the screen that the map no longer covers. 我确实记得尝试旋转整个地图,但是遇到了这样的问题:一旦旋转地图矩形,您最终会在屏幕上看到白色的三角形区域,而地图不再覆盖该区域。 It should be possible somehow to oversize the map so that it bleeds off the screen when straight to an extent that it still covers the entire screen regardless of its rotation. 应该可以以某种方式放大地图的大小,以使它在笔直时从屏幕上流血到一定程度,无论其旋转如何,地图仍会覆盖整个屏幕。 I don't know whether this would mess with other aspects of Google Maps though. 我不知道这是否会与Google Maps的其他方面混淆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM