)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

How to read the JSON input file instead of JS file ?

Platform: jQuery |
Control: ejMap |
Published Date: January 6, 2015 |
Last Revised Date: June 25, 2019
Tags: maps, json, js, javascript

The following steps help you meet the requirement.

Step 1: Create a sample map and include the necessary script files.

Step 2: Use the SyncfusionLocation.json script file for reference.

HTML

[SyncfusionLocation.json]
sync = '[{ "Name": "Chennai", "Country": "India", "latitude": 13.0839, "longitude": 80.27,"Description": "Chennai", "Address": "EYMARD" },{ "Name": "North Carolina ", "Country": "United States", "latitude": 35.5, "longitude": -80, "Description": "USA", "Address": "RDU" }]';    

Step 3: In order to read the JSON file data, you need to parse the JSON file as follows:

HTML

    var json= JSON.parse(sync); 

In the above example, the SyncfusionLocation file variable, or sync, has been parsed and stored in a variable called json.

Step 4: Assign the parsed json data to markers.

HTML

       markers: json, 

In the following code example is used markers and markerTemplate, to denote json data in the “World Map”, based on its respective latitude and longitude.

Refer the following online documentation links for more details about markers and markerTemplate.

http://help.syncfusion.com/ug/js/documents/mapelements.htm

Sample Location for Markers:

http://js.syncfusion.com/demos/web/#!/azure/map/DataMarkers

HTML

<script type="text/javascript">   
     jQuery(function ($) {         
      var json= JSON.parse(sync);
      $("#container").ejMap({                     
                   . . .             
                 layers: [
                       {
                                          . . .              
                               markers: json,
                                                                            . . .         
                               shapeData: world_map
                                                 }
                 ]
             });
         });        
    </script>  

Screenshot:

C:\Users\Adithi\AppData\Roaming\Skype\My Skype Received Files\IMG_06012015_042644.png

Figure 1: Map with Markers

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon