This page can't load Google Maps correctly

I am trying to get map from address but there are appear some error like You have exceeded your request quota for this API in my console so can anyone help me to fix this.

My Javascript code look like below so please check and let me know if i am doing something wrong...

Thanks!

    ?php
$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$address.'sensor=false');
$output = json_decode($geocode); //Store values in variable 
//print_r($output);

if($output-status == 'OK'){ // Check if address is available or not
    $latitude = $output-results[0]-geometry-location-lat; //Returns Latitude
    $longitude = $output-results[0]-geometry-location-lng; // Returns Longitude
}
else {
    echo "Sorry we can't find this location.Check the details again!";
}

?
script type="text/javascript"
    jQuery(document).ready(function () {
        // Define the latitude and longitude positions
        var latitude = parseFloat("?php echo $latitude; ?"); // Latitude get from above variable
        var longitude = parseFloat("?php echo $longitude; ?"); // Longitude from same
        var latlngPos = new google.maps.LatLng(latitude, longitude);

        // Set up options for the Google map
        var myOptions = {
            zoom: 14,
            center: latlngPos,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            zoomControlOptions: true,
            zoomControlOptions: {
                style: google.maps.ZoomControlStyle.LARGE
            }
        };

        // Define the map
        map = new google.maps.Map(document.getElementById("map"), myOptions);

        // Add the marker
        var marker = new google.maps.Marker({
            position: latlngPos,
            map: map,
            title: "Your Location"
        });

    });
/script

Topic google-maps map api Wordpress javascript

Category Web


There's nothing wrong with your code , its just that the daily limit to access Google API is over.

Google API has a daily free quota. For Google Places API it's 2500 requests per day and 10 requests per second. If you want to use more than that, I would suggest to enable billing. If you still want to use the free quota, please wait for a day to get those 2500 requests again.

Note : The quota is based on specific accounts. Please make your own API key using Google API console if you're using a random one.

To know more about this refer this link

Hope this helps.


Welcome to the new world of Google Maps :( You now have to have your credit card linked to your Google Maps API. They give you $250 a month of "credit" so you will likely not get charged, but you do have to have the card linked.

https://venturebeat.com/2018/05/02/google-maps-platform-arrives-with-pay-as-you-go-billing-free-support-and-cloud-requirement-starting-june-11/

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.