2014年04月

google marker animation break

I found some code for google maps marker movement. So i just wanna animate marker moving from one location to another. Here in this code for loop is for marker moving, i want to stop the loop when marker arrives on half route. How i can break for loop?



I Tried with if statment, but nothing, when site being loaded immediately execute that if statement and then set marker and for loop begins. If you have simpler
method for marker animation please share.



Here is the code



    <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>GeekOnJava: Directions Complex</title>


<style>
html{height:100%;}
body{height:100%;margin:0px;font-family: Helvetica,Arial;}
</style>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

var map;
var directionDisplay;
var directionsService;
var stepDisplay;

var position;
var marker = [];
var polyline = [];
var poly2 = [];
var poly = null;
var startLocation = [];
var endLocation = [];
var timerHandle = [];


var speed = 0.000005, wait = 1;
var infowindow = null;

var myPano;
var panoClient;
var nextPanoId;

var startLoc = new Array();
startLoc[0] = 'Aranji Janoša, Zrenjanin';


var endLoc = new Array();
endLoc[0] = 'Hunjadi Janoša, Zrenjanin';


var Colors = ["#FF0000", "#00FF00", "#0000FF"];


function initialize() {

infowindow = new google.maps.InfoWindow(
{
size: new google.maps.Size(150,50)
});

var myOptions = {
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

address = 'Serbia'
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
map.fitBounds(results[0].geometry.viewport);

});
// setRoutes();
}


function createMarker(latlng, label, html) {
// alert("createMarker("+latlng+","+label+","+html+","+color+")");
var contentString = '<b>'+label+'</b><br>'+html;
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: label,
zIndex: Math.round(latlng.lat()*-100000)<<5
});
marker.myname = label;


google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(contentString);
infowindow.open(map,marker);
});
return marker;
}
function setRoutes(){

var directionsDisplay = new Array();

for (var i=0; i< startLoc.length; i++){

var rendererOptions = {
map: map,
suppressMarkers : true,
preserveViewport: true
}
directionsService = new google.maps.DirectionsService();

var travelMode = google.maps.DirectionsTravelMode.DRIVING;

var request = {
origin: startLoc[i],
destination: endLoc[i],
travelMode: travelMode
};

directionsService.route(request,makeRouteCallback(i,directionsDisplay[i]));

}


function makeRouteCallback(routeNum,disp){
if (polyline[routeNum] && (polyline[routeNum].getMap() != null)) {
startAnimation(routeNum);
return;
}
return function(response, status){

if (status == google.maps.DirectionsStatus.OK){

var bounds = new google.maps.LatLngBounds();
var route = response.routes[0];
startLocation[routeNum] = new Object();
endLocation[routeNum] = new Object();


polyline[routeNum] = new google.maps.Polyline({
path: [],
strokeColor: '#FFFF00',
strokeWeight: 3
});

poly2[routeNum] = new google.maps.Polyline({
path: [],
strokeColor: '#FFFF00',
strokeWeight: 3
});

// For each route, display summary information.
var path = response.routes[0].overview_path;
var legs = response.routes[0].legs;


disp = new google.maps.DirectionsRenderer(rendererOptions);
disp.setMap(map);
disp.setDirections(response);


//Markers
for (i=0;i<legs.length;i++) {
if (i == 0) {
startLocation[routeNum].latlng = legs[i].start_location;
startLocation[routeNum].address = legs[i].start_address;
// marker = google.maps.Marker({map:map,position: startLocation.latlng});
marker[routeNum] = createMarker(legs[i].start_location,"start",legs[i].start_address,"green");
endLocation[routeNum].latlng = legs[i].end_location;
endLocation[routeNum].address = legs[i].end_address;
var steps = legs[i].steps;

for (j=0;j<steps.length;j++) {
var nextSegment = steps[j].path;
var nextSegment = steps[j].path;

for (k=0;k<nextSegment.length;k++) {
polyline[routeNum].getPath().push(nextSegment[k]);
//bounds.extend(nextSegment[k]);
}
}

}

}

polyline[routeNum].setMap(map);
//map.fitBounds(bounds);
startAnimation(routeNum);
var g = marker[0].getPosition();
var z = endLocation[0].latlng;
if (g == z){
alert("kraj");
}

} // else alert("Directions request failed: "+status);

}

}

var lastVertex = 1;
var stepnum=0;
var step = 50; // 5; // metres
var tick = 100; // milliseconds
var eol= [];
//----------------------------------------------------------------------
function updatePoly(i,d) {
// Spawn a new polyline every 20 vertices, because updating a 100-vertex poly is too slow
if (poly2[i].getPath().getLength() > 20) {
poly2[i]=new google.maps.Polyline([polyline[i].getPath().getAt(lastVertex-1)]);
// map.addOverlay(poly2)
}

if (polyline[i].GetIndexAtDistance(d) < lastVertex+2) {
if (poly2[i].getPath().getLength()>1) {
poly2[i].getPath().removeAt(poly2[i].getPath().getLength()-1)
}
poly2[i].getPath().insertAt(poly2[i].getPath().getLength(),polyline[i].GetPointAtDistance(d));
} else {
poly2[i].getPath().insertAt(poly2[i].getPath().getLength(),endLocation[i].latlng);
}
}
//----------------------------------------------------------------------------

function animate(index,d) {
if (d>eol[index]) {
var g = marker[index].setPosition(endLocation[index].latlng);
marker[index].setPosition(endLocation[index].latlng);
return;
}
var p = polyline[index].GetPointAtDistance(d);

//map.panTo(p);
marker[index].setPosition(p);
updatePoly(index,d);
timerHandle[index] = setTimeout("animate("+index+","+(d+step)+")", tick);
}

//-------------------------------------------------------------------------

function startAnimation(index) {
if (timerHandle[index]) clearTimeout(timerHandle[index]);
eol[index]=polyline[index].Distance();
map.setCenter(polyline[index].getPath().getAt(0));

poly2[index] = new google.maps.Polyline({path: [polyline[index].getPath().getAt(0)], strokeColor:"#FFFF00", strokeWeight:3});

timerHandle[index] = setTimeout("animate("+index+",50)",2000); // Allow time for the initial map display
}

//----------------------------------------------------------------------------



</script>
</head>
<body onload="initialize()">

<div id="tools">

<button onclick="setRoutes();">Start</button>

</div>

<div id="map_canvas" style="width:100%;height:100%;"></div>

</body>
</html>




How to find IP address of a client (customer)

I need the client(customer) ip address of the browser.



This is the client page in php



<?php
$xml_request = '<XMLRequest>
<RequestType>ServiceRequest</RequestType>
<RequestLogin>test</RequestLogin>
</XMLRequest>';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://testserver.com/test_xml/request.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_ENCODING,'gzip');
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_request);
echo curl_exec($ch); curl_close($ch);
?>


This is my server page
'http://testserver.com/test_xml/request.php' in php



$service_request = file_get_contents('php://input');

echo 'Client IP Address: '. $_SERVER['REMOTE_ADDR'];


But here its 'ECHO' my own server IP.



How i get the client browser IP to my server



Answers

Your're doing http request from your own server, that's why you get your server IP. To solve your problem you have to make changes in client page (eg. add additional parameter to XML Request or add custom header with client IP address)



Thank you.



Answers

Are you hosting the website? Then it would show your own IP, when you viewed the website.



Answers

It will not work like that because you call the Server page from your client page, which both sit on your server and use PHP. So in your scenario the server is asking itself for his IP address (client & server are the same).



You could put $_SERVER['REMOTE_ADDR'] on your client page. But I also don't understand why you have a 'client' and a 'server' page both written in PHP and one calls the other with curl. It seems like horrible practice.



Answers

As answered by Jumes, you are using the correct Server variables. If you run your script from your server console [or by some other method] , your server Ip address will show up.



You may want to try running the client script from different machines [having different public IP addresses] to see a visible difference.





Question

I was injured on the job. Spervisor told me to take the day off and go to the doctor. I went to the doctor had xray. I went back to work and when I asked her about getting help for my arm she fired me for no valid reason. Can I still get worker comp to have the surgery I need for my arm?



Answer

Once you suffer an industrial injury the WC benefits kick in. It does not matter if you were filred a minute afterwards, you get the same benefits. However, it is illegal to fire someone merely because they suffered an industrial injury. If you are a member of a union, go to the shop stewart. If not, interview several WC atorneys to find out what they think about adding a discrimination claim.



Answer

yes





Log4j2: Ability to log data with different log levels in multi user environment

I'm using log4j2 in oracle adf 12c application.



One of the requirements of our customer is to have different log levels for different logged-in users and also to change the log levels dynamically for a user.Also the Administrator should have a control to stop all the logging.



i.e Lets say 'User A' needs Trace log level and 'User B' needs Error log level. If both the users are logged in simultaneously, the application should log in Trace level for 'User A' and in Error level for 'User B'. And if the 'User B' wants to log in FATAL level he should be able to change the configuration dynamically.



Following is the log4j2 config file.



    <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace">
<MapFilter onMatch="ACCEPT" operator="or">
<KeyValuePair key="$${ctx:LOGLEVELYN}" value="Y"/>
</MapFilter>
<Appenders>
<File name="file" fileName="./adfAppCustomLogs/TestLog4j2.log">
<PatternLayout>
<Pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} %-5level %class %L %M - %msg%xEx%n</Pattern>
</PatternLayout>
</File>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%m%n"/>
</Console>
<Routing name="AppRouting">
<Routes pattern="$${ctx:LOGGEDSESSIONID}">
<!-- This route is chosen if ThreadContext has no value for key ROUTINGKEY. -->
<Route key="$${ctx:LOGGEDSESSIONID}">
<RollingFile name="Rolling-ALL" fileName="./adfAppCustomLogs/DefaultAll.log"
filePattern="./adfAppCustomLogs/archive/${date:yyyy-MM}/DefaultAll-%d{MM-dd-yyyy}-%i.txt.gz">
<PatternLayout>
<Pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} %-5level %t %msg%xEx%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
</RollingFile>
</Route>
<!-- This route is chosen if ThreadContext has value 'user' for key ROUTINGKEY. -->
<Route>
<RollingFile name="Rolling-OTHER-${ctx:LOGGEDSESSIONID}"
fileName="./adfAppCustomLogs/${ctx:LOGINID}-${ctx:LOGGEDSESSIONID}.log"
filePattern="./adfAppCustomLogs/archive/${date:yyyy-MM}/${ctx:LOGINID}-%d{MM-dd-yyyy}-%i.txt.gz">
<PatternLayout>
<Pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} %-5level %t %msg%xEx%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
<!-- <DefaultRolloverStrategy max="100"/> -->
</RollingFile>
</Route>
</Routes>
</Routing>
<Async name="async" bufferSize="1000" includeLocation="true">
<AppenderRef ref="AppRouting"/>
</Async>
</Appenders>
<Loggers>
<Root level="trace">
<!--<AppenderRef ref="file" level="DEBUG"/> -->
<AppenderRef ref="async"/>
<!-- Uncomment the following if you want the log to be printed in weblogic console -->
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>


I'm trying to create multiple loggers with a different loglevel for each one but nothing worked.



It would be great if you can give me some pointers or hints.





Why does the heat in my car only get hot when i mash on the gas hard?

It is a vacum problem.

Your controls are all on vacum lines.

Check the lines under the dash.

- ALSO TRY BLEEDING SYSTEM, LOW COOLANT MAY CAUSE "SHUFFLING". COOLANT BYPASSES THE HEATER CORE UNDER LOW FLOW CONDITIONS. INCREASE SPEED WILL CAUSE HIGHER VOLUME TO CORE, CAUSING HEAT WHILE UNDER ACCELERATION ONLY.



↑このページのトップヘ