2012-04-29 67 views
10

我一直在閱讀https://developers.google.com/maps/documentation/javascript/overlays一段時間,我似乎無法獲得我的地圖工作的自定義圖標。如何使用Google Maps API v3的自定義圖標創建標記?

這裏是我的javascript:

var simplerweb = new google.maps.LatLng(55.977046,-3.197118); 
var marker; 
var map; 

function initialize() { 
    var myOpts = { 
     center: simplerweb, 
     zoom:  15, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOpts); 
    marker = new google.maps.Marker({ 
     map:  map, 
     draggable: true, 
     animation: google.maps.Animation.DROP, 
     position: simplerweb 
    }); 
    google.maps.event.addListener(marker, 'click', toggleBounce); 
} 

function toggleBounce() { 
    if (marker.getAnimation() != null) { 
    marker.setAnimation(null); 
    } else { 
    marker.setAnimation(google.maps.Animation.BOUNCE); 
    } 
} 

與gmaps一個初學者的任何指針?

回答

28
marker = new google.maps.Marker({ 
    map:map, 
    // draggable:true, 
    // animation: google.maps.Animation.DROP, 
    position: new google.maps.LatLng(59.32522, 18.07002), 
    icon: 'http://cdn.com/my-custom-icon.png' // null = default icon 
    }); 
+0

不工作,我做錯了什麼? http://pastebin.com/Vk001VJM – andy

+1

http://cdn.com/my-custom-icon.png只是一個虛擬地址,你應該使用一個有效的地址到一個有效的圖像,你也宣佈了兩次相同的變種「simplerweb」,你可以刪除它 –

+0

我現在覺得自己像一個白癡。 圖像可以託管了嗎? – andy

-4
LatLng hello = new LatLng(X, Y);   // whereX & Y are coordinates 

Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), 
       R.drawable.university); // where university is the icon name that is used as a marker. 

mMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(icon)).position(hello).title("Hello World!")); 

mMap.moveCamera(CameraUpdateFactory.newLatLng(hello)); 
+3

android!= java腳本 – dit

+2

java script!== javascript – stephenmurdoch

相關問題