Advertisement:

Author Topic: Google Maps shows for some milliseconds and then stops  (Read 5925 times)

gripa

  • Newbie
  • *
  • Posts: 1
Google Maps shows for some milliseconds and then stops
« on: August 03, 2016, 12:35:09 am »
I just installed the latest version of OSClass.

Everything works, except Google Maps.
After a very short time it is giving the information that Google Maps was not loaded correctly, with the extra information :  see Java script console for technical details.

I don't understand what this and if this is an installation error or something else ?


Web-Media

  • Sr. Member
  • ****
  • Posts: 453
  • Web
Re: Google Maps shows for some milliseconds and then stops
« Reply #1 on: August 03, 2016, 10:38:51 am »
 Usage of the Google Maps APIs now requires a key.
If you are using the Google Maps API on localhost or your domain was not active prior to June 22nd, 2016, it will require a key going forward. To fix this problem, please see the Google Maps APIs documentation to get a key and add it to your application: https://developers.google.com/maps/documentation/javascript/get-api-key
Locate the file that contains the Google Maps script code on your website, and append your API key to it as a parameter:
1
<script src="//maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" async="" defer="defer" type="text/javascript"></script>
If there aren’t other parameters, just add ?key=YOUR_API_KEY at the very end of the src path; otherwise, add &key=YOUR_API_KEY instead, like this:
1
<script src="//maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&key=YOUR_API_KEY" async="" defer="defer" type="text/javascript"></script>
Obviously, in both cases you must replace YOUR_API_KEY with your actual API key code.
6.  Enjoy!

adol420

  • Newbie
  • *
  • Posts: 1
Re: Google Maps shows for some milliseconds and then stops/ solucionado
« Reply #2 on: August 03, 2016, 03:30:12 pm »
Solucionado problema API de google.
Primero obtener clave API.
buscar en el pluguins google maps el archivo index.php y sustituir :  '<script src="https://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>'  - por  -     <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"
  type="text/javascript"></script>
reemplazar YOUR API KEY por la clave api obtenida en https://console.developers.google.com/apis/

gooki

  • Newbie
  • *
  • Posts: 22
Re: Google Maps shows for some milliseconds and then stops
« Reply #3 on: August 03, 2016, 08:16:58 pm »
Thank you for the solution!

Warley

  • Newbie
  • *
  • Posts: 4
Re: Google Maps shows for some milliseconds and then stops
« Reply #4 on: August 09, 2016, 08:03:21 pm »
I can not fix this problem.
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.googleapis.com/maps/api/js?key=AIzaSyCPmRx2XLu10GTyr_OcnetEr3SGqPUHjLY"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');

?>
I Need Help Someone can tell me what is missing in this code.
Someone who got support could pass the certl code or me show Gossip

Warley

  • Newbie
  • *
  • Posts: 4
Re: Google Maps shows for some milliseconds and then stops
« Reply #5 on: August 09, 2016, 08:12:44 pm »
Someone could spend the full code

esince96

  • Newbie
  • *
  • Posts: 11
Re: Google Maps shows for some milliseconds and then stops
« Reply #6 on: September 01, 2016, 09:14:43 pm »
Hi Web Media,

where is that google map script found ?

Thanks,

Esince96


SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Google Maps shows for some milliseconds and then stops
« Reply #7 on: September 04, 2016, 12:39:37 am »
I am using Google Maps version 2.1.6 which comes with latest Osclass version and all works fine without the need to register an API key.

Script is found where ALL plugins are located ie. \oc-content\plugins\google_maps


Regards,
Eric
« Last Edit: September 04, 2016, 12:41:15 am by SmaRTeY »

cartagena68

  • issues
  • Hero Member
  • *
  • Posts: 1198
Re: Google Maps shows for some milliseconds and then stops
« Reply #8 on: September 04, 2016, 02:08:19 am »
I am using Google Maps version 2.1.6 which comes with latest Osclass version and all works fine without the need to register an API key.

Script is found where ALL plugins are located ie. \oc-content\plugins\google_maps


Regards,
Eric

Actually that is not correct, google map now require the API key to work correctly.
If you have an old domain the map will work but if you check the console on chrome you will see a note that say that the API key is missing.
With a new domain the map will not work and will give the error specified in the title.

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Google Maps shows for some milliseconds and then stops
« Reply #9 on: September 04, 2016, 02:32:34 am »
Thanks cartagena68, well it is correct in my specific scenario I guess but I was not aware of the API Domain fact.
Interesting to see how Google is going about this 'update'..... 8)

I am using Google Maps version 2.1.6 which comes with latest Osclass version and all works fine without the need to register an API key.

Script is found where ALL plugins are located ie. \oc-content\plugins\google_maps


Regards,
Eric

Actually that is not correct, google map now require the API key to work correctly.
If you have an old domain the map will work but if you check the console on chrome you will see a note that say that the API key is missing.
With a new domain the map will not work and will give the error specified in the title.

esince96

  • Newbie
  • *
  • Posts: 11
Re: Google Maps shows for some milliseconds and then stops
« Reply #10 on: September 07, 2016, 12:52:03 am »
Thanks SmaRTey and cartagena68, found the location for the code and it worked (with my API key)

bakunine

  • Newbie
  • *
  • Posts: 20
Re: Google Maps shows for some milliseconds and then stops
« Reply #11 on: September 07, 2016, 01:46:47 am »
I had the same problem, and I got a funny solution: I've got an API key and, following their advice, I made the "restrictions" for specific url (my website, of course). And it didn't work.
So, I disable the API restriction, keeping the API key, and now everything works perfect. :D

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Google Maps shows for some milliseconds and then stops
« Reply #12 on: September 08, 2016, 12:31:10 am »
Hi bakunine,

I just made the change to the url using the Googlemaps API key with restrictions to my site and it works just fine.
Since my *old* setting/url also worked without issues maybe that explains me not having the issue you mentioned but I was wondeing if the issue could be related to either the mentioned 5 minute (or more) delay by Google before API key is active OR if you maybe used an url format that created the restriction issue. I used the format Google has set as an example ie. *.domain.com/*

Regards,
Eric

I had the same problem, and I got a funny solution: I've got an API key and, following their advice, I made the "restrictions" for specific url (my website, of course). And it didn't work.
So, I disable the API restriction, keeping the API key, and now everything works perfect. :D

adleee84

  • Newbie
  • *
  • Posts: 21
Re: Google Maps shows for some milliseconds and then stops
« Reply #13 on: September 10, 2016, 02:10:52 pm »
Hi,

Is it enough just to update the API key in the plugin file? Or do i need to update API key in every page that has map?

I am using Google Maps version 2.1.6 which comes with latest Osclass version and all works fine without the need to register an API key.

Script is found where ALL plugins are located ie. \oc-content\plugins\google_maps


Regards,
Eric

cityking

  • Newbie
  • *
  • Posts: 3
Re: Google Maps shows for some milliseconds and then stops
« Reply #14 on: September 13, 2016, 09:24:34 am »
Dear All

I had replace the API key and everythin looks fine. I can used the google map.But when I used the search on the homepage. the page will be show erro:


Warning: Cannot modify header information - headers already sent by (output started at /public_html/oc-content/plugins/google_maps/index.php:1) in /home/cityking/public_html/oc-includes/osclass/utils.php on line 1743

When I restore the google map plugins "index.php" . the homepage search can be used.  Anyone has this problem?

« Last Edit: September 13, 2016, 11:08:10 am by cityking »