嗨我有一个在Eclipse中使用phonegap开发的android应用程序.我想在我的应用程序中添加一个地图.我怎么做?
我需要为此添加一个插件吗?如果是,那么哪一个,我将在哪里获得?
我希望能够根据地图网址加载特定位置的地图.地图URL将保存在数据库中.我已设法获取URL但无法弄清楚如何添加地图.
任何帮助?
解决方法:
在phonegap android应用程序上映射(谷歌)
获取当前的纬度和经度
navigator.geolocation.getCurrentPosition(onSuccess, one rror);
function onSuccess(position) {
var current_lat = position.coords.latitude;
var current_lng = position.coords.longitude;
}
function one rror(error)
{
alert(error)
}
您可以使用插件或不使用插件在phonegap app中显示地图
1)使用插件
2)没有插件
HTML
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<div id="map_canvas" style="width:100%;height:100%; position:absolute;"></div>
JAVASCRIPT
var secheltLoc = new google.maps.LatLng(your_latitude, your_longitude);
var myMapOptions = {
zoom: 16
,center: secheltLoc
,mapTypeId: google.maps.MapTypeId.HYBRID
};
var theMap = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);
var image = "img/map_pin.png"
var marker = new google.maps.Marker({
map: theMap,
draggable: false,
position: new google.maps.LatLng(latitude, longitude),
visible: true,
icon: image,
title:restaurantName // Title
});
var myOptions = {
content: ""
,disableAutopan: false
,maxWidth: 0
,pixelOffset: new google.maps.Size(-140, -110)
,pixelOffset: new google.maps.Size(140, 110)
,zIndex: null
,BoxStyle: {
background: "url('tipBox.gif') no-repeat"
,opacity: 0.90
}
,closeBoxMargin: "10px 2px 2px 2px"
,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
,infoBoxClearance: new google.maps.Size(1, 1)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: false
};
var contentString = '<div class="map_anotaion_title">Yor Content</div>'; //Address on pin click
var infowindow = new google.maps.InfoWindow({
content: contentString
});
infowindow.open(theMap,marker);
google.maps.event.addListener(marker, "click", function (e) {
infowindow.open(theMap,marker);
});
地图中的多个标记
var locations = new Array(3);
locations [0] = new Array(3);
locations[0][0] = "Bondi Beach";
locations[0][3] = 23.0300;
locations[0][4] = 72.4000;
locations[0][5] = 3;
locations [1] = new Array(3);
locations[1][0] = 'Coogee Beach'
locations[1][6] = 21.3600;
locations[1][7] = 71.1500;
locations[1][8] = 4;
locations [2] = new Array(3);
locations[2][0] = 'Cronulla Beach';
locations[2][9] = 22.3200;
locations[2][10] = 73.0000;
locations[2][11] = 73.0000;
var map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 6,
center: new google.maps.LatLng(locations[0][12], locations[0][13]),
mapTypeId: google.maps.MapTypeId.HYBRID
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][14], locations[i][15]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。