Tell me how such a thing is realized: There is a block where a city is selected, for example, Moscow and London. And I need to 1) specify an office label in each city 2) when you click on a city (in a block) move to a specific label

thank

    1 answer 1

    To do this, use the Google Maps API Markers.

    It's pretty simple, here is a sample code:

    // инициализация Π³ΡƒΠ³Π»ΠΎΠΊΠ°Ρ€Ρ‚Ρ‹ var map = new google.maps.Map(document.getElementById('map'), { // ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΠΈ ΠΊΠ°Ρ€Ρ‚Ρ‹ }); // ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ - ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Ρ‹ офиса // lat - ΡˆΠΈΡ€ΠΎΡ‚Π° // lng - Π΄ΠΎΠ»Π³ΠΎΡ‚Π° function chnangePositionOnMap(lat, lng) { var myLatLng = {lat: lat, lng: lng}; /* это Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΡΡ‚Π°Π²ΠΈΡ‚ΡŒ ΠΌΠ°Ρ€ΠΊΠ΅Ρ€ Ссли Π½ΡƒΠΆΠ½ΠΎ var marker = new google.maps.Marker({ position: myLatLng, map: map, title: 'тСкст ΠΌΠ°Ρ€ΠΊΠ΅Ρ€Π°' }); */ // Π° это Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠ΅Ρ€Π΅ΠΉΡ‚ΠΈ ΠΊ Π΄Π°Π½Π½Ρ‹ΠΌ ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Π°ΠΌ Π½Π° ΠΊΠ°Ρ€Ρ‚Π΅ map.setCenter(myLatLng); }