reading textfile into google maps using javascript and jqueryhttp://forums.asp.net/t/1794444.aspx/1?reading+textfile+into+google+maps+using+javascript+and+jqueryTue, 24 Apr 2012 08:05:59 -040017944444939831http://forums.asp.net/p/1794444/4939831.aspx/1?reading+textfile+into+google+maps+using+javascript+and+jqueryreading textfile into google maps using javascript and jquery <p>The code that follows is the code in my .aspx page. The map displays but the markers do not. The file is not being read and therefore the marker coordinates dont get retrieved for the marker locations. I tried debugging but the debugger never hits on the debugger line.</p> <pre class="prettyprint">&lt;%@ Page Title=&quot;&quot; Language=&quot;C#&quot; MasterPageFile=&quot;~/MasterPage.master&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;MarkerOptions.aspx.cs&quot; Inherits=&quot;MarkerOptions&quot; %&gt; &lt;asp:Content ID=&quot;Content1&quot; ContentPlaceHolderID=&quot;ContentPlaceHolder1&quot; Runat=&quot;Server&quot;&gt; &lt;script src=&quot;/Scripts/jquery-1.5.1.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; &lt;script type=&quot;text/javascript&quot; src=&quot;http://maps.googleapis.com/maps/api/js?key=AIzaSyCjtIboyk_zcd4SoE9fzNoGNzt_tIqG8jY&amp;sensor=false&quot;&gt;&lt;/script&gt; &lt;script type =&quot;text/javascript&quot;&gt; var map; function initialize() { var latlng = new google.maps.LatLng(-34.397, 150.644); var myOptions = { zoom: 5, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById(&quot;map&quot;), myOptions); var marker, i; debugger; var file = &quot;X:\ASP.Net\GoogleMaps\GMAP\MarkerCoordinates.txt&quot;; //file:\\X:\ASP.Net\GoogleMaps\GMAP\MarkerCoordinates.txt $.get(file,function(txt){ var lines = txt.responseText.split(&quot;\n&quot;); for (i = 0; i &lt; lines.length; i&#43;&#43;) { marker = new google.maps.Marker({ position: new google.maps.LatLng(lines.split(&quot;,&quot;)[0], lines.split(&quot;,&quot;)[1]), map: map }); // var infowindow = new google.maps.InfoWindow({ // content: 'Location info:&lt;br/&gt;Country Name:&lt;br/&gt;LatLng:' // }); // google.maps.event.addListener(marker, 'click', function () { // // Calling the open method of the infoWindow // infowindow.open(map, marker); // }); } window.onload = initialize; &lt;/script&gt; &lt;h2&gt;MarkerOptions Demo:&lt;/h2&gt; &lt;div id =&quot;map&quot; style=&quot;height: 750px; width: 900px; top: 60px; left: 126px; position: absolute;&quot;&gt;&lt;/div&gt; &lt;/asp:Content&gt;</pre> <p><br> <br> </p> 2012-04-19T00:30:50-04:004942366http://forums.asp.net/p/1794444/4942366.aspx/1?Re+reading+textfile+into+google+maps+using+javascript+and+jqueryRe: reading textfile into google maps using javascript and jquery <p>Hi,</p> <p>I suggest you debugging with IE Developer Tools. Any more question, please feel free to reply.</p> 2012-04-20T07:51:29-04:004947093http://forums.asp.net/p/1794444/4947093.aspx/1?Re+reading+textfile+into+google+maps+using+javascript+and+jqueryRe: reading textfile into google maps using javascript and jquery <p>I guess you didn't see the debugger; code line</p> <p>it seems rather strange that no one seems to be familiar with how to read a text file which resides in your solution folder (Vs2010) into a javascript variable either using jquery or javascript.</p> 2012-04-23T18:48:55-04:004947300http://forums.asp.net/p/1794444/4947300.aspx/1?Re+reading+textfile+into+google+maps+using+javascript+and+jqueryRe: reading textfile into google maps using javascript and jquery <p>That is because it typically isn't done.&nbsp; The browser won't trust you, and it rightly shouldn't.&nbsp; No page should allow you to read random files off your local system, that's a major security issue.&nbsp; You would be better off having the server read the file for you, then parsing it into a collection, and using the Javascript Serializer to generate a JSON string to include in the page.</p> 2012-04-23T21:23:38-04:004947419http://forums.asp.net/p/1794444/4947419.aspx/1?Re+reading+textfile+into+google+maps+using+javascript+and+jqueryRe: reading textfile into google maps using javascript and jquery <p>Bear with me as I'm not an web developer but a vb.net developer. So I would retrieve the text file contents via code in the code behind? How would I pass that string to the javascript? I need the contents of that file to generate the google map markers. &nbsp;I am currently reading local text files through an asp.net literal control for other content on my webpages, is that not proper form? I am doing so as it's far easier to update content in a text file than to find every occurence of it in a website and just have that file read in where necessary.</p> 2012-04-24T00:55:20-04:004947443http://forums.asp.net/p/1794444/4947443.aspx/1?Re+reading+textfile+into+google+maps+using+javascript+and+jqueryRe: reading textfile into google maps using javascript and jquery <p>Collect the contents into a collection of some sort, then you should be able to do something like (sorry, this is C#, but VB.net will be similiar):</p> <pre class="prettyprint">using System.Web.Script.Serialization; var oSerializer = new JavaScriptSerializer(); sJSON = oSerializer.Serialize(myCollection); Page.ClientScript.RegisterStartupScript(GetType(), &quot;mapdata&quot;, &quot;mapdata=&quot; &#43; sJSON &#43; &quot;;&quot;, true);</pre> <p></p> <p>I often this with LINQ and pass that to the serializer, but a collection should work just as well.&nbsp; If not pass myCollection.AsEnumerable(), but I think you can pass it directly.&nbsp; After that, you should have an array of objects that you can iterate through in your webpage.&nbsp; Sort of like:</p> <pre class="prettyprint">for (var i = 0; i &lt; window.mapdata.length; i++) { var obj = window.mapdata[i]; var lat = obj["latitude"]; var lng = obj["longitude"]; ... Set up Google map stuff here with lat/lng }</pre> <p><br> <br> </p> <p></p> <p></p> <p></p> 2012-04-24T01:58:43-04:004947452http://forums.asp.net/p/1794444/4947452.aspx/1?Re+reading+textfile+into+google+maps+using+javascript+and+jqueryRe: reading textfile into google maps using javascript and jquery <p>As for reading in a text file and passing it in an ASP literal, it sounds like what you really want is a UserControl.&nbsp; You can put whatever you want in it and then reference that anywhere in your web pages, and it will basically copy in the HTML where you placed the UserControl.&nbsp; Of course I usually have something more than just text, but sometimes not.&nbsp; Sort of like</p> <p>Contents of default.aspx:</p> <pre class="prettyprint">&lt;%@ Register src=&quot;Map.ascx&quot; tagPrefix=&quot;something&quot; tagName=&quot;map&quot; %&gt; .... &lt;something:map ID=&quot;map1&quot; runat=&quot;server&quot;/&gt; ....</pre> <p>Contents of Map.ascx:</p> <pre class="prettyprint">&lt;input type="text" style="font-weight: bold;" ID="formtext1" /&gt;</pre> <p>Then if you change Map.ascx for whatever reason, you get it everywhere you have that UserControl.<br> <br> <br> </p> 2012-04-24T02:08:44-04:004948023http://forums.asp.net/p/1794444/4948023.aspx/1?Re+reading+textfile+into+google+maps+using+javascript+and+jqueryRe: reading textfile into google maps using javascript and jquery <p>Thank you, I came up with a similar soultion after your last post</p> 2012-04-24T08:05:59-04:00