Is there a method to obtain over 10 markers on the map?

Trying to find nearby places from my current location. The issue I'm currently facing is that I'm only able to see 10 markers on the map, and no more locations are being displayed. Is there a way to bypass or resolve this problem? I've come across information online stating that Google limits the number of markers to 10.

googleMaps.js:

// Initialize Variables
    var map;
    var infowindow;
    var service;
    var markers = [];

    // DOM Initialization
    $('#details').hide();
    // Checkbox Initialization
    $('#gym').prop('checked', true);
    $('#park').prop('checked', true);
    $('#store').prop('checked', true);
    $('#museum').prop('checked', true);
    $('#cafe').prop('checked', true);

    // Initialize GeoLocation
    geoLocationInit();

    // Google Maps Section
    function geoLocationInit() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(success, fail);
        } else {
            alert("Browser not supported");
        }
    }

    function success(position) {
        var latval = position.coords.latitude;
        var Ingval = position.coords.longitude;
        myLatLng = new google.maps.LatLng(latval, Ingval);
        initMap(myLatLng);
    }

    function fail() {
        alert("it fails");
    }

    // Map Initialization
    function initMap(myLatLng) {
        map = new google.maps.Map(document.getElementById('map'), {
            center: myLatLng,
            zoom: 12
        });

        var request = {
            location: myLatLng,
            radius: 8047,
            types: ['cafe', 'gym', 'park', 'store', 'museum']
        };

        infowindow = new google.maps.InfoWindow();
        service = new google.maps.places.PlacesService(map);
        service.nearbySearch(request, callback);
        map.addListener('idle', performSearch);
    }

    function callback(results, status) {
        if (status == google.maps.places.PlacesServiceStatus.OK) {
            for (var i = 0; i < results.length; i++) {
                addMaker(results[i]);
            }
        }
    }

    // Adding Marker
    function addMaker(place) {
        service.getDetails({
            placeId: place.place_id
        }, function (place, status) {
            if (status === google.maps.places.PlacesServiceStatus.OK) {
                // Code here to add Marker to the map
            }
        });
    }

    // Marker Filters for Gym, Park, Store, Museum, Zoo, Cafe
    function gymMarkers() {
        // Code for gym markers
    }

    function parkMarkers() {
        // Code for park markers
    }

    function storeMarkers() {
        // Code for store markers
    }

    function museumMarkers() {
        // Code for museum markers
    }

    function zooMarkers() {
        // Code for zoo markers
    }

    function cafeMarkers() {
        // Code for cafe markers
    }

front.blade.php

@extends('layouts.master')

@section('content')

    <!-- This is a *view* - HTML markup that defines the appearance of your UI -->
    <div id='searchBar'>
        <p>Search: <strong data-bind="text: location"></strong></p>
        // Checkbox options for gym, park, store, museum, zoo, cafe
    </div>

    <div class="container">
        {{--Google maps--}}
        <div id="map"></div>

        {{--Cafe details--}}
        <div id="details" style="visibility:false">
            // Details displayed when clicking on a marker
        </div>

        {{--Review--}}
        <div>
            <ul class="reviews"></ul>
        </div>
        {{--Example--}}
        <div>
            <ul class="example"></ul>
        </div>
    </div>

@endsection

Click Here for Image of Map

Answer №1

Your JavaScript code seems to be utilizing the places nearby search feature. This search can provide up to 60 results across 3 pages, as mentioned in the Places API web service documentation:

Typically, each nearby or text search query will return a maximum of 20 establishment results. However, it is possible to receive up to 60 results spread across three pages. If more than 20 results are expected, a next_page_token will be included in the search response. This token can be used to fetch the next set of results by passing it to the pagetoken parameter of a new search query.

The behavior of the places library in the Maps JavaScript API mirrors this setup. The nearbySearch() method's callback function returns a PlaceSearchPagination object as the third parameter. This pagination object includes a hasNextPage property to check for additional results, allowing you to call the nextPage() method if needed.

An example showcasing how to utilize pagination in nearby searches can be found here: https://developers.google.com/maps/documentation/javascript/examples/place-search-pagination

It's important to remember that the Places API functions more as a tool for retrieving prominent results within a specified area, rather than a comprehensive database search. If you receive fewer than 20 results on the first page, it indicates that Google couldn't identify enough prominent establishments in that area.

I hope this explanation helps clarify your query.

[1] https://developers.google.com/maps/documentation/javascript/reference#PlacesService

[2] https://developers.google.com/maps/documentation/javascript/reference#PlaceSearchPagination

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Converting a timestamp from PHP in JSON format to date and time using JavaScript

Within the JSON file, there is a timestamp associated with each user login. An example of this timestamp is: timestamp: "1541404800" What steps should be taken to convert this timestamp into date and time format? ...

What could be the reason for my code generating the error [$http:badreq]?

I'm currently attempting to retrieve JSON data from a certain URL and am having trouble getting it to work. Despite going through the Angular documentation and other resources, I still can't pinpoint the issue due to my limited experience with An ...

Sending a JSON object from JSP to JavaScript using AJAX

Is there a way to transfer JSON values from JSP to JavaScript as an object using AJAX without resorting to global JavaScript variables, which can expose the JSON content in the page's source? The desired scenario is as follows: The JSP URL is opene ...

I attempted to shift my focus back to the input box, but for some reason, it doesn't want to cooperate

I'm having trouble getting the focus to return to the input box in my form after an invalid entry triggers an alert box. I've written what should be the correct code, but for some reason, it's not working as expected. Here's the code s ...

Is there a way to determine the app bar height within a React Material UI application?

I'm trying to create a full-screen image for the opening of my website using React and Material UI. Here's a snippet of my JSX code with the default Material UI theme: <AppBar> //code in between </AppBar> <Container sx={{margin: ...

Whenever I attempt to start the server using npm run server, I encounter the following error message: "Error: Unable to locate module './config/db'"

This is the server.jsx file I'm working with now: Take a look at my server.jsx file Also, here is the bd.jsx file located in the config folder: Check out the db.jsx file Let me show you the structure of my folders as well: Explore my folder structur ...

When starting the application by navigating to "http://localhost/<myapp>/public", a routing conflict in Laravel occurs due to the project folder being located in the default Apache directory

Currently, I am embarking on the journey of building apps using the Laravel framework. I am following a video tutorial in Spanish available at this link: https://www.youtube.com/watch?v=A-BL8Ir7puE&list=PLZ2ovOgdI-kWWS9aq8mfUDkJRfYib-SvF&index=2 ...

Exploring the world of lighting and shadows in WebGL and Three.js

I'm having difficulty focusing lights on specific targets, specifically the main character, while also darkening the background. Additionally, I'm experiencing issues with the shadows not working properly in my code snippet related to lights and ...

The combination of NextJS and Firebase Auth using the GoogleAuthProvider is powerful

I am encountering challenges while trying to integrate firebase authentication with Google Provider in NextJS. I have set up the necessary environment variables and successfully established a connection with firebase. However, I keep running into an error ...

What is the best way to consistently and frequently invoke a REST API in Angular 8 using RxJS?

I have developed a REST API that retrieves a list of values. My goal is to immediately invoke this API to fetch values and store them in a component's member variable. Subsequently, I plan to refresh the data every five minutes. Upon conducting some ...

Twists and turns as I mix up Kineticjs

After scrambling my puzzle, I now need it to be rotated. Can anyone help me with this? Thanks :) fillPatternImage:imageObj, x:-pieceWidth*i/2, y:-pieceHeight*j/2, stroke: "#000000", ...

Discovering the object and its parent within a series of nested arrays

Is there a way to locate an object and its parent object within a nested array of unknown size using either lodash or native JavaScript? The structure of the array could resemble something like this: name: 'Submodule122'</p> I have been ...

Node.js process.exec() function allows you to asynchronously spawn a subprocess

After writing the code, I ran it and found that the terminal was unresponsive with no output, causing the program to be stuck. var util=require('util') var exec=require('child_process').exec; exec('iostat 5',function(err,stdo ...

Tips for properly sending a JWT token

When working on my angular application, I encountered an issue while trying to send a jwt token as a header for request authorization. The error 500 was triggered due to the jwt token being sent in an incorrect format. Here is how I am currently sending it ...

Retrieving ID of an element to be animated with jQuery

I have a sprite image that changes background position when hovered over, and while it's currently working, I'm looking for a more efficient way to achieve this. I need to apply this effect to several images and am exploring ways to avoid duplica ...

An issue occurred during compilation with 1 error: The required dependency could not be located

Encountering an issue in a Vue component while attempting to import another JavaScript file located in the services/AuthenticationService directory. Error message: Module not found: Error: Can't resolve '@/services/AuthenticationService'. ...

The Laravel error message "stdClass::count() method is not defined" indicates that the count

I am working on paginating my JSON response, but I encountered an error message: Call to undefined method stdClass::count() The JSON response is from the Laravel API using guzzle ...... Below is the code snippet from my controller: public function i ...

Transferring radio button selections from a form to Google Analytics upon submission

I have a form where I can capture user selections from radio buttons and a drop-down element using the .blur() event. However, I am struggling with pushing this data to Google Analytics (GA) when the user clicks the submit button. Currently, my script loo ...

Using a forEach loop within the RequestAnimationFrame function

I am currently developing a project using THREEjs and would like to organize it in the following manner: class Blah scene : new THREE.Scene() renderer : new THREE.WebGLRenderer() camera : new THREE.PerspectiveCamera() ...

Changing the main domain of links with a specific class attribute during an onmousedown event - is it possible?

We are facing a situation where we have numerous webpages on our blog that contain links from one domain (domain1.com) to another domain (domain2.com). In order to avoid manual changes, we are attempting to achieve this without altering the link (href). Th ...