javascript - How to dynamically generate different google maps -


here issue have. have many businesses , want show google maps each business (all in 1 html page).

for each business have:

  • the latitude , longitude (always).
  • the address not street number.

question.

how can insert google map each business using lat/long or business using google map api?

difficulties

-using id each business not ideal.

-how can pass latitude/longitude javascript function insert map?

here general idea of want do.

assume have array of businesses contains information each business.

foreach($businesseslist $businessname =>binfo) {        list($about, addresstext, $lat, $long) = $binfo         <div> $businessname</div>        <div> $about</div>        <div class='map'> 

//insert google maps inside div each business using $lat, $long , google maps api.

            </div>  } 

i dont experience javascript , jquery work php

i can set array containing google maps embed code , embedded code each business dont that.

e.g addressarray =['business1'=>'embed code copied google maps.', .....]

ps feel free ask clarifications.

thanks in advance.

so have php array needed data latlng

then can iterate on over php , render html each item

having html id each business map is ok

some meta code:

<?php  $myplaces = [     [         'address'=>'example 1, ny',         'lat'=>30.123456,         'lng'=>50.123456     ],     [         'address'=>'example 2, la',         'lat'=>40.123456,         'lng'=>50.123456     ],     //as many ];  $unique_id = 0; foreach($myplaces $place){         ?>     <h1><?php echo $place['address']; ?></h1>     <div id="map_<?php echo $unique_id; ?>"></div>     <script>     var pos = {lat: <?php echo $place['lat']; ?>, lng: <?php echo $place['lng']; ?>};     var map = new google.maps.map(document.getelementbyid('map_<?php echo $unique_id; ?>'), {         zoom: 4,         center: pos      });     var marker = new google.maps.marker({         position: pos,         map: map     });     </script>     <?php     $unique_id++; } ?> 

docs: https://developers.google.com/maps/documentation/javascript/adding-a-google-map

dont forget include google maps script proper api key


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -