Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load `google map` to `div` directly to container?

I require to load a map to my page. I have the URL for that which is :

https://servicepoints.dhlecommerce.com/?lnglat=3.16327,101.69507&language=en

if I paste the above url, I am getting the map loaded in the browser. Same way I am trying to load this map in to my web page. But nothing loads..

what is the correct way to load the above map in to my web page?

Here is my try:

$(function(){

  var mapURL = "https://servicepoints.dhlecommerce.com/?lnglat=3.16327,101.69507&language=en";

  $("#map").load(mapURL);

});

Live Demo

like image 689
user2024080 Avatar asked Apr 17 '18 04:04

user2024080


People also ask

How do I embed a map in HTML?

Embed a map or directionsClick Share or embed map. Click Embed map. Copy the text in the box. Paste it into the HTML of your website or blog.


2 Answers

Url is not directly load on div .So you can append iframe on div like this to load map.

$(function() {
  var html = '<iframe src="https://servicepoints.dhlecommerce.com/?lnglat=3.16327,101.69507&language=en"></iframe>';
  $("#map").append(html);
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='map'><map>
<div id='map1'><map>

Or If you don't want to use iframe you cane use embed tag.

var html='<embed src="https://servicepoints.dhlecommerce.com/?lnglat=3.16327,101.69507&language=en" width=200 height=200 />';
 $("#map").append(html);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='map'></div>
like image 189
4b0 Avatar answered Sep 22 '22 18:09

4b0


You can trigger DIV load Event

HTML iframe Tag

The tag specifies an inline frame.

An inline frame is used to embed another document within the current HTML document.

$(function(){
	$('div[onload]').trigger('onload');
});


function  displayMap() {
	 var mapURL = "https://servicepoints.dhlecommerce.com/?lnglat=3.16327,101.69507&language=en";
   
	$("#map").append("<iframe src=" + mapURL +"></iframe>"); 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<div onload="displayMap()" id ="map"></div>

You can display your map without iframe

HTML object Tag

The tag defines an embedded object within an HTML document. Use this element to embed multimedia (like audio, video, Java applets, ActiveX, PDF, and Flash) in your web pages.

<div> 
    <object type="text/html" data="https://servicepoints.dhlecommerce.com/?lnglat=3.16327,101.69507&language=en" width="800px" height="300px" style="overflow:auto;border:1px solid">
    </object>
</div>

Difference between and tag

like image 30
Aman Kumar Avatar answered Sep 22 '22 18:09

Aman Kumar