var Line = new google.maps.Polyline({
    editable: false,
    strokeColor: '#FF0000',
    strokeOpacity: 1.0,
    strokeWeight: 2

var Rect=new google.maps.Polygon({
    editable: false,
    strokeColor: '#FF0000',
    strokeOpacity: 1.0,
    strokeWeight: 2

the object Line is poly Line and Rect is Polygon .The question is how can i retrive it's type from Object name ,Like Rect.type or Line.type ?


Add a listener to your drawing manager and check using obj.type to check for the type of shape drawn. Eg:

var mapOptions = {
    zoom: 4,
    center: {lat: 39.810866, lng: -104.990347}
var circleOptions = {
    fillColor: '#ffff00',
    fillOpacity: 0.2,
    strokeColor: '#ffff00',
    strokeWeight: 2,
    strokeOpacity: 0.3,
    clickable: false,
    editable: true,
    zIndex: 1

var map = new google.maps.Map(document.getElementById('map'), mapOptions);
var drawingManager = new google.maps.drawing.DrawingManager({
                      drawingMode: null,
                      drawingControl: true,
                      drawingControlOptions: {
                          position: google.maps.ControlPosition.TOP_RIGHT,
                          drawingModes: ['circle', 'polygon', 'rectangle']
                      markerOptions: {icon: 'markerImage.png'},
                      circleOptions: circleOptions
google.maps.event.addListener(drawingManager, 'overlaycomplete', 

function onOverlayComplete(shape) {

if(shape == null || (shape.type.length == 0 || shape.type == null)) { return;  }
 if (shape.type == 'polygon') {

 if (shape.type == 'circle') {


Use your own image for the marker icon or search for one online.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.