Author Topic: Using google maps in product  (Read 7886 times)

nav007_2000

  • Beginner
  • *
  • Posts: 20
Re: Using google maps in product
« Reply #15 on: July 25, 2012, 07:15:15 am »
Hi Ivus

Custom fields are

Address ID 4
City ID 5
Post code ID 6

ivus

  • Full Member
  • ***
  • Posts: 534
  • - YAY me... proud member of the 500 club...
Re: Using google maps in product
« Reply #16 on: July 25, 2012, 07:29:56 am »
OK try this.

Code: [Select]

<?php

$address NULL;
$city NULL;
$postcode NULL;
$country "US";

foreach ($this->product->customfieldsSorted['normal'] as $customfields) :

switch ($customfields->virtuemart_custom_id) {
case 4:
$address $customfields->display;
break;
case 5:
$city $customfields->display;
break;
case 6:
$postcode $customfields->display;
break;
}

endforeach;

$fullAddress nl2br($address).','.$city.','.$postcode.','.$country;
$fulladdressEsc ereg_replace(' ','+',$fullAddress);
$geocode file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$fulladdressEsc.'&sensor=false');
$output json_decode($geocode);
$googlemapLat $output->results[0]->geometry->location->lat;
$googlemapLong $output->results[0]->geometry->location->lng;

?>

<style>
.__loc_mapContainer {
width:934px;
display:block;
height:305px;
margin-top:30px;
margin-left:auto;
margin-right:auto;
position:relative;
cursor:pointer;
clear:both;
border:solid 3px #434244;
background-color:#FFFFFF;
}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initializeMap() {
var latlng = new google.maps.LatLng(<?php echo $googlemapLat?>,<?php echo $googlemapLong?>);
var settings = {
zoom: 14,
center: latlng,
mapTypeControl: false,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), settings);
var companyMarker = new google.maps.Marker({
position: latlng,
map: map,
zIndex: 3});
}
</script>
<div id="map_canvas" class="__loc_mapContainer"></div>
<script type="text/javascript">
initializeMap();
</script>


nav007_2000

  • Beginner
  • *
  • Posts: 20
Re: Using google maps in product
« Reply #17 on: July 25, 2012, 09:42:36 am »
That didnt bring up the map. Nor did it show up an error. Maybe the custom fields are not going into the array? :(

nav007_2000

  • Beginner
  • *
  • Posts: 20
Re: Using google maps in product
« Reply #18 on: July 26, 2012, 01:35:30 am »

nav007_2000

  • Beginner
  • *
  • Posts: 20
Re: Using google maps in product
« Reply #19 on: July 26, 2012, 01:40:35 am »
where can i place the class on my server? would that be within the joomla directory or the virtue mart directory?