2016-04-21 10 views
5

मार्ग केवल बनाने में PlaceId बनाएं अगर मैं LatLng या स्ट्रिंग का उपयोग पैरामीटर लेकिन मैं PlaceId से इसे बनाने की जरूरत है, लेकिन यह काम नहीं करता हैगूगल मैप्स एपीआई (जे एस) एक मार्ग संकेतक

उदाहरण:

directionsService.route({ 
     origin: {'placeId': 'ChIJc1lGdwfP20YR3lGOMZD-GTM'}, 
     destination: {'placeId': 'ChIJdTGhqsbP20YR6DZ2QMPnJk0'}, 
     waypoints: [{stopover: true, location: new google.maps.Place('ChIJRVj1dgPP20YRBWB4A_sUx_Q')}], 
     optimizeWaypoints: true, 
     travelMode: google.maps.TravelMode.DRIVING 
    } 
+0

आप इस संबंधित [तो सवाल] की जाँच करने की कोशिश की है (http://stackoverflow.com/questions/33990153/पास-जगह-आईडी-स्थान-टू-गंतव्य--google-नक्शे-api में)? आपके त्रुटि लॉग क्या हैं? – abielita

+0

मैंने कोशिश की लेकिन बिना परिणाम के। placeId केवल मूल और गंतव्य के लिए काम करता है। मुझे परिणाम के रूप में नहीं मिला है –

उत्तर

4

बस google.maps.Place ऑब्जेक्ट को मार्ग बिंदु के रूप में पास करने की आवश्यकता है। उदाहरण के लिए:

directionsService.route({ 
    origin: { placeId: "ChIJc1lGdwfP20YR3lGOMZD-GTM" }, 
    destination: { placeId: "ChIJdTGhqsbP20YR6DZ2QMPnJk0" }, 
    waypoints: [{ stopover: true, location: { placeId: "ChIJRVj1dgPP20YRBWB4A_sUx_Q" } }], 
    optimizeWaypoints: true, 
    travelMode: google.maps.TravelMode.DRIVING 
} 

स्थान,, वेपॉइंट का स्थान निर्दिष्ट एक LatLng के रूप में एक google.maps.Place वस्तु के रूप में या एक स्ट्रिंग जो जिओकोड हो जाएगा के रूप में। इस लाइन पर Uncaught TypeError: google.maps.Place is not a constructor:

Google Maps - Direction Services Documentation

Here's the JsFiddle

3

मैं पोस्ट कोड के साथ एक जावास्क्रिप्ट त्रुटि मिलती है

waypoints: [{stopover: true, location: new google.maps.Place('ChIJRVj1dgPP20YRBWB4A_sUx_Q')}], 

आपको लगता है कि location उसी तरह आप के साथ क्या निर्दिष्ट करने की आवश्यकता origin और destination स्थान आईडी:

में
waypoints: [{ 
    stopover: true, 
    location: {'placeId':"ChIJRVj1dgPP20YRBWB4A_sUx_Q"} 
}], 

विवरण:

Google.maps.Place वस्तु विनिर्देश

placeId | टाइप करें: स्ट्रिंग स्थान की जगह आईडी (जैसे व्यवसाय या रुचि का बिंदु)। स्थान आईडी Google मानचित्र डेटाबेस में किसी स्थान का अद्वितीय पहचानकर्ता है। ध्यान दें कि जगह आईडी किसी स्थान की पहचान करने का सबसे सटीक तरीका है। यदि संभव हो, तो आपको placeQuery के बजाय placeId निर्दिष्ट करना चाहिए। किसी स्थान अनुरोध को स्थान API पर किसी भी अनुरोध से पुनर्प्राप्त किया जा सकता है, जैसे टेक्स्टशर्च। प्लेस आईडी को जियोकोडिंग एपीआई से अनुरोधों से भी पुनर्प्राप्त किया जा सकता है। अधिक जानकारी के लिए, overview of place IDs देखें।

proof of concept fiddle

कोड स्निपेट:

function initialize() { 
 
    var map = new google.maps.Map(document.getElementById("map_canvas")); 
 
    var directionsService = new google.maps.DirectionsService(); 
 
    var directionsDisplay = new google.maps.DirectionsRenderer({ 
 
    map: map 
 
    }); 
 
    directionsService.route({ 
 
    origin: { 
 
     'placeId': 'ChIJc1lGdwfP20YR3lGOMZD-GTM' 
 
    }, 
 
    destination: { 
 
     'placeId': 'ChIJdTGhqsbP20YR6DZ2QMPnJk0' 
 
    }, 
 
    waypoints: [{ 
 
     stopover: true, 
 
     location: { 
 
     'placeId': "ChIJRVj1dgPP20YRBWB4A_sUx_Q" 
 
     } 
 
    }], 
 
    optimizeWaypoints: true, 
 
    travelMode: google.maps.TravelMode.DRIVING 
 
    }, function(response, status) { 
 
    if (status === 'OK') { 
 
     directionsDisplay.setDirections(response); 
 
    } else { 
 
     window.alert('Directions request failed due to ' + status); 
 
    } 
 
    }); 
 
} 
 
google.maps.event.addDomListener(window, "load", initialize);
html, 
 
body, 
 
#map_canvas { 
 
    height: 100%; 
 
    width: 100%; 
 
    margin: 0px; 
 
    padding: 0px 
 
}
<script src="https://maps.googleapis.com/maps/api/js"></script> 
 
<div id="map_canvas"></div>

संबंधित मुद्दे