Заметка о том как настроить показ гуглокарт в SOBI2.
Особенности в том что российские адреса несколько отличаются от европейских поэтому будут некоторые правки кода подсчета координат.
Пример основан на настроках демо-сайта sigsiu.net - http://joomla.sigsiu.net/administrator/index2.php?option=com_sobi2&task=editFields (demo/demo).
1. Зайди в Конфигурация-Управление пользовательскими полями.
2. Создать 2 поля типа inputbox:
- имя поля field_latitude, метка поля Latitude, css-класс inputbox.
- имя поля field_longitude, метка поля Longitude, css-класс inputbox.
3. Создать одно поле типа text code:
- имя поля field_fetchcoordinates, метка поля Fetch coordinates,
text code:
<script type="text/javascript" language="JavaScript"> /* adjust here the field names if they are not correct */ var apiKey = "{googleApiKey}"; var cityField = 'field_city'; var houseField = 'field_house'; var streetField = 'field_street'; var latitudeField = 'field_latitude'; var longitudeField = 'field_longitude'; function fetchCoordinates() { /* here you should not change anything */ var gRequest = null; var city = document.getElementById(cityField).value; var street = document.getElementById(streetField).value; var house = document.getElementById(houseField).value; { var gRequest = "http://maps.google.com/maps/geo?q=" +city+ "+" +street+ "+" +house+ "&callback=getCoordinates&output=JSON&key="+apiKey; var scriptObj = document.createElement("script"); scriptObj.setAttribute("type", "text/javascript"); scriptObj.setAttribute("src", gRequest); document.getElementsByTagName("head").item(0).appendChild(scriptObj); } } function getCoordinates(data) { switch(data.Status.code) { case 610: /* you can change the error message here */ alert("Api key not valid: {googleApiKey}"); break; case 603: case 602: case 601: case 500: /* you can change the error message here */ alert("Cannot get coordinates for this address"); break; case 200: document.getElementById(latitudeField).value = data.Placemark[0].Point.coordinates[1]; document.getElementById(longitudeField).value = data.Placemark[0].Point.coordinates[0]; break; } } </script> <!-- You can change the "value" (The label on the button) here --> <input type="button" class="button" onclick="fetchCoordinates();" value="Fetch Coordinates"/>