gpt4 book ai didi

iphone - 使用javascript从iOS Corona平台中的谷歌地图获取当前位置

转载 作者:行者123 更新时间:2023-11-29 03:43:13 24 4
gpt4 key购买 nike

我非常坚持从 Corona sdk 中的谷歌地图获取当前位置,我已经尝试过谷歌地理位置,我尝试了以下解决方案,但在电晕中它没有显示用户的当前位置 thisthis 还有

<script src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script>
var map;
function initialize() {
var myOptions = {
zoom: 8,
panControl: false,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL
},
mapTypeControl: false,
scaleControl: false,
streetViewControl: false,
overviewMapControl: false,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'),
myOptions);

// Try HTML5 geolocation
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);

var infowindow = new google.maps.InfoWindow({
map: map,
position: pos,
content: 'Location found using HTML5.'
});

map.setCenter(pos);
}, function() {
handleNoGeolocation(true);
});
} else {
// Browser doesn't support Geolocation
handleNoGeolocation(false);
}
}

function handleNoGeolocation(errorFlag) {
if (errorFlag) {
var content = 'Error: The Geolocation service failed.';
} else {
var content = 'Error: Your browser doesn\'t support geolocation.';
}

var options = {
map: map,
position: new google.maps.LatLng(60, 105),
content: content
};

var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>

最佳答案

使用 native.newMapView() 的 Corona native map 不是在网络浏览器中运行或直接使用设备应用程序的“Google map ”。在 Apple 上,我们使用他们内置的 Map SDK,该 SDK 恰好使用驱动 Apple map 应用程序的引擎。在 Android 上,我们使用 Google 的 Map SDK。

要点是您不能在使用 native.newMapView() 的 Corona 应用程序中使用这样的 JavaScript。如果您使用 webView,您可能会得到它,因为您可以运行 JavaScript 并且您的 webView 可以嵌入 Google 网页 map 。这就是为什么我不得不问这个问题。现在我们知道了......

Corona SDK 有多个 API 调用,可与 native.newMapView 配合使用,让您获取地址和位置信息。请参阅:

http://docs.coronalabs.com/api/type/Map/index.html

关于iphone - 使用javascript从iOS Corona平台中的谷歌地图获取当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18074024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com