2013-02-03 51 views
0

试图创建PhoneGap移动应用程序。全新的移动应用程序,phonegap和JS,所以忍受着我。这是我在哪里:无法将标记添加到移动谷歌地图

<script type="text/javascript"> 
function initialize() { 
    var mapOptions = { 
     center: new google.maps.LatLng(40.710,-73.994), //New york, NY 
     zoom: 8, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), 
     mapOptions) 
}; 

因此,地图在浏览器中呈现很好。当添加我在许多教程中发现的以下内容时,它拒绝呈现任何内容。我正在尝试在我创建的googlemap/index.html页面中执行所有这些操作。

<script type="text/javascript"> 
function initialize() { 
    var mapOptions = { 
     center: new google.maps.LatLng(40.710,-73.994), //New york, NY 
     zoom: 8, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), 
     mapOptions); 
    var LatLng = new google.maps.LatLng(40.710,-73.994) 
    var marker = new.google.maps.Marker({ 
     position: myLatLng, 
     title: "hello world!" 
     }); 
    marker.setMap(map); 
}; 

当我添加以下内容时,整个页面拒绝呈现。

基本上,我使用上面的方法来显示谷歌地图,我试图添加一个别针到中心位置。似乎很简单,但证明超出了我的能力。

+0

我有LogCat运行(日食),我找不到任何记录,当我旋转了这个页面。所以我不确定哪里有任何渲染问题会被堵住。 – BamBamBeano

回答

1

您对此行语法错误:

var marker = new.google.maps.Marker({ 

注意,还有就是new运营商和类名之间的点。

要修复,更换线以上:

var marker = new google.maps.Marker({ 

映射快乐!

PS:在(桌面)浏览器的控制台中报告了错误,我不确定在Android设备上您会看到相同的错误。