Wysłane przez
lagren
Wyswietlanie mapy w opsie szczegolwym bez wpisywania recznie koordynatow.
U mnie dziala wg :
Step 1
Goto - Configuration - Custom Fields Manager
Create a Custom field called 'field_longitude' without the quotes
Fileld Label = Longitude
Field Type = Inputbox
Click Save
Step 2
Create a Custom Field called 'field_latitude' without the quotes
Fileld Label = Latitude
Field Type = Inputbox
Click Save
Step 3
Make sure all of the following fields exist...If not recreate them....I deleted Country when I first set this up...The fetch failed until I put it back....
field for post code 'field_postcode' type = inputbox
field for city 'field_city' type = inputbox
field for street 'field_street' type = inputbox
field for country 'field_country' type = inputbox
Step 4
Create a new field type "text code" (formerly called custom code)
Cut and paste the script from this link into the code box
skrypt:
<script type="text/javascript" language="JavaScript">
/* adjust here the field names if they are not correct */
var apiKey = "{googleApiKey}";
var postalCodeField = 'field_postcode';
var cityField = 'field_city';
var streetField = 'field_street';
var countryField = 'field_country';
var latitudeField = 'field_latitude';
var longitudeField = 'field_longitude';
function fetchCoordinates() {
/* here you should not change anything */
var gRequest = null;
var postalcode = document.getElementById(postalCodeField).value;
var city = document.getElementById(cityField).value;
var street = document.getElementById(streetField).value;
var country = document.getElementById(countryField).value;
if(postalcode == '' || city == '' || street == '' || country == '' ) {
/* you can change the error message here */
alert("Proszę wypełnić pola adresowe");
}
else {
var gRequest = "http://maps.google.com/maps/geo?q=" +street+ "+" +postalcode+ "+" +city+ "+" +country+ "&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).appe ndChild(scriptObj);
}
}
function getCoordinates(data) {
switch(data.Status.code) {
case 610:
/* you can change the error message here */
alert("Api key nieprawidłowy: {googleApiKey}");
break;
case 603:
case 602:
case 601:
case 500:
/* you can change the error message here */
alert("Nie można pobrać koordynatów geograficznych dla tego adresu");
break;
case 200:
document.getElementById(latitudeField).value = data.Placemark[0].Point.coordinates[1];
document.getElementById(longitudeField).value = data.Placemark[0].Point.coordinates[0];
break;
}
}
***********
<!-- You can change the "value" (The label on the button) here -->
<input type="button" class="button" onclick="fetchCoordinates();" value="Pobierz automatycznie koordynaty geograficzne do GoogleMaps"/>
Step 5
Goto "View Configuration" - "Google Maps"
Step 6
Enter your google maps API
Step 7
Check the box to show google maps.
Set "Map Latitude Field" to field_latitude
Set "Map Longitude Field" to field_longitude
Step 8 - Testing
Pozostaje konfiguracja (nazwy pol, ukrys szer dl w opisie szczegolwym etc)