• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

121
Views
GoogleMaps get center location of current view

I'm using google maps js in my project.PRoject shows locations by marker in googlemaps. I can add marker with some butotn but marker needs lat and long values so i put the locations[0].lat,locations[0].lon,It works fine but not user friendly.

So, what i want to do is make a static marker into the center of the map, when user slides the map , it will still stay in the middle when the user scrolls the map then user clicks the add location button then it adds.

It can also done with add marker in current view center

Current add location code, map and title is global, index comes from document.ready foreach loop

function addLocation(){  
      var myLatlng = new google.maps.LatLng(allMarkers[0].position.lat()+0.20, allMarkers[0].position.lng()+0.20);

                  var marker = new google.maps.Marker({
            position: latlng,
            map: map,
            title: title,
            draggable: true,
            index:index
        });
 
 
        marker.addListener('dragend', handleEvent);
          marker.addListener("click", () => {
            
              
            allMarkers[index].isDeleted='1';
            allMarkers[index].setMap(null);
            

             });
        allMarkers.push(marker);
}
about 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error