Hello everyone, I use the example from Google

Now, I would like to know how to change center location from city to another city like this map in
please can you help me to know how becouse im new in google map
and i have anthore question in my local host the marker appear but online it dosnt
my map in this click in sign location to see it.

Dani AI

Generated

Short, practical note for (and thanks to for the simple-example idea): changing the map center is just a client-side call — either set the initial center in the MapOptions when you create the map, or call map.setCenter() / map.panTo() from an event (click, dropdown change, etc.). To show all markers and re-center automatically use map.fitBounds() after you add markers. See the Maps API reference for the map methods and LatLng-literal examples. (developers.google.com)

Example (minimal) workflow to switch cities:

  1. create the map with a default center and zoom;
  2. when the user picks a city call map.setCenter({lat: xx, lng: yy}) (optionally map.setZoom());
  3. if you place multiple markers for that city build a LatLngBounds and call map.fitBounds(bounds) so all markers are visible.

A common reason markers show on localhost but not online is an API / server configuration problem. Check the browser console first for Google Maps loader errors (MissingKeyMapError, RefererNotAllowedMapError, BillingNotEnabledMapError) — those point to API key, billing, or API-activation issues. Verify you are loading the Maps JavaScript API with a valid key and that billing is enabled on the project. Also check API-key restrictions in the Cloud Console (HTTP referrers / API restrictions) — wrong restrictions will block production pages. (developers.google.com)

Server-side checklist (phpsqlajax flow): use DevTools Network to inspect the AJAX/XHR that fetches your PHP endpoint — look for 404/500 responses or an empty reply; open the endpoint URL directly in a browser to see raw output. Enable PHP error logging or temporarily enable display_errors on your dev server to catch fatal errors or DB connection failures. These steps will quickly reveal whether the problem is the Maps key/config or the server script/DB. (developer.chrome.com)

Recommended immediate steps: make a single-file test page that loads the Maps API with a known-working key (no restrictions while testing), place one marker and call map.setCenter() manually. When that works, reintroduce your AJAX/PHP code and use the Network tab + PHP logs to fix any server errors, then add UI to switch cities.

Hi,

I suggest you to try with this simple google map.

Please check and let me know.

Thanks,
Ajay

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.