*

MB Themes

Re: Help. For Google maps, location
« Reply #15 on: October 07, 2016, 03:56:33 PM »
@Paulo
Then it is problem that osclass did not care yet.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

Re: Help. For Google maps, location
« Reply #16 on: March 16, 2020, 06:48:09 PM »
This is my index.php
Code: [Select]
<?php
/*
Plugin Name: Google Maps
Plugin URI: http://www.osclass.org/
Description: This plugin shows a Google Map on the location space of every item.
Version: 2.1.6
Author: Osclass & kingsult
Author URI: http://www.osclass.org/
Plugin update URI: http://www.osclass.org/files/plugins/google_maps/update.php
*/

    
function google_maps_location() {
        
$item osc_item();
        
osc_google_maps_header();
        require 
'map.php';
    }

    
// HELPER
    
function osc_google_maps_header() {
        echo 
'<script src="https://maps.google.com/maps/api/js?key=AIzaSyC86j93jSD1utlzg8egiVn5qMWUqktN2_s&sensor=false" type="text/javascript"></script>';
        echo 
'<style>#itemMap img { max-width: 140em; } </style>';
    }

    function 
insert_geo_location($item) {
        
$itemId $item['pk_i_id'];
        
$aItem Item::newInstance()->findByPrimaryKey($itemId);
        
$sAddress = (isset($aItem['s_address']) ? $aItem['s_address'] : '');
        
$sCity = (isset($aItem['s_city']) ? $aItem['s_city'] : '');
        
$sRegion = (isset($aItem['s_region']) ? $aItem['s_region'] : '');
        
$sCountry = (isset($aItem['s_country']) ? $aItem['s_country'] : '');
        
$address sprintf('%s, %s, %s, %s'$sAddress$sCity$sRegion$sCountry);
        
$response osc_file_get_contents(sprintf('http://maps.google.com/maps/geo?q=%s&output=json&sensor=false'urlencode($address)));
        
$jsonResponse json_decode($response);
        if (isset(
$jsonResponse->Placemark) && count($jsonResponse->Placemark[0]) > 0) {
            
$coord $jsonResponse->Placemark[0]->Point->coordinates;
            
ItemLocation::newInstance()->update (array('d_coord_lat' => $coord[1]
                                                      ,
'd_coord_long' => $coord[0])
                                                ,array(
'fk_i_item_id' => $itemId));
        }
    }

    
osc_add_hook('location''google_maps_location');

    
osc_add_hook('posted_item''insert_geo_location');
    
osc_add_hook('edited_item''insert_geo_location');

?>

It works perfect

Thank you, yes works perfect :)

Re: Help. For Google maps, location
« Reply #17 on: March 16, 2020, 08:06:50 PM »
This is my index.php
Code: [Select]
<?php
/*
Plugin Name: Google Maps
Plugin URI: http://www.osclass.org/
Description: This plugin shows a Google Map on the location space of every item.
Version: 2.1.6
Author: Osclass & kingsult
Author URI: http://www.osclass.org/
Plugin update URI: http://www.osclass.org/files/plugins/google_maps/update.php
*/

    
function google_maps_location() {
        
$item osc_item();
        
osc_google_maps_header();
        require 
'map.php';
    }

    
// HELPER
    
function osc_google_maps_header() {
        echo 
'<script src="https://maps.google.com/maps/api/js?key=AIzaSyC86j93jSD1utlzg8egiVn5qMWUqktN2_s&sensor=false" type="text/javascript"></script>';
        echo 
'<style>#itemMap img { max-width: 140em; } </style>';
    }

    function 
insert_geo_location($item) {
        
$itemId $item['pk_i_id'];
        
$aItem Item::newInstance()->findByPrimaryKey($itemId);
        
$sAddress = (isset($aItem['s_address']) ? $aItem['s_address'] : '');
        
$sCity = (isset($aItem['s_city']) ? $aItem['s_city'] : '');
        
$sRegion = (isset($aItem['s_region']) ? $aItem['s_region'] : '');
        
$sCountry = (isset($aItem['s_country']) ? $aItem['s_country'] : '');
        
$address sprintf('%s, %s, %s, %s'$sAddress$sCity$sRegion$sCountry);
        
$response osc_file_get_contents(sprintf('http://maps.google.com/maps/geo?q=%s&output=json&sensor=false'urlencode($address)));
        
$jsonResponse json_decode($response);
        if (isset(
$jsonResponse->Placemark) && count($jsonResponse->Placemark[0]) > 0) {
            
$coord $jsonResponse->Placemark[0]->Point->coordinates;
            
ItemLocation::newInstance()->update (array('d_coord_lat' => $coord[1]
                                                      ,
'd_coord_long' => $coord[0])
                                                ,array(
'fk_i_item_id' => $itemId));
        }
    }

    
osc_add_hook('location''google_maps_location');

    
osc_add_hook('posted_item''insert_geo_location');
    
osc_add_hook('edited_item''insert_geo_location');

?>

It works perfect

I noticed, your API Code working but my code not wroking :(